{"record":{"id":"abe499069c5e51cf","repo":"tursodatabase/turso","slug":"http-error-status-response-status","errorCode":null,"errorMessage":"HTTP error! status: ${response.status}","messagePattern":"HTTP error! status: (.+?)","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/protocol.ts","lineNumber":302,"sourceCode":"  let response: Response;\n  try {\n    response = await fetch(`${ctx.url}/v3/cursor`, buildFetchOptions(ctx, JSON.stringify(request), signal));\n  } catch (error) {\n    wrapAbortError(error);\n  }\n\n  if (!response.ok) {\n    let errorMessage = `HTTP error! status: ${response.status}`;\n    try {\n      const errorBody = await response.text();\n      const errorData = JSON.parse(errorBody);\n      if (errorData.message) {\n        errorMessage = errorData.message;\n      }\n    } catch {\n      // If we can't parse the error body, use the default HTTP error message\n    }\n    throw new DatabaseError(errorMessage);\n  }\n\n  const reader = response.body?.getReader();\n  if (!reader) {\n    throw new DatabaseError('No response body');\n  }\n\n  const decoder = new TextDecoder();\n  let buffer = '';\n  let cursorResponse: CursorResponse | undefined;\n\n  // First, read until we get the cursor response (first line)\n  try {\n    while (!cursorResponse) {\n      const { done, value } = await reader.read();\n      if (done) break;\n\n      buffer += decoder.decode(value, { stream: true });","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/serverless/javascript/src/protocol.ts#L284-L320","documentation":"DatabaseError thrown when the streaming /v3/cursor endpoint answers a non-2xx status; the runtime message interpolates the actual code (e.g. 'HTTP error! status: 401'). The client first tries to parse the response body as JSON and use its message field — only when the body is not parseable JSON (or has no message) does the generic status text survive.","triggerScenarios":"401/403 from an invalid or expired authToken on any execute/batch call; 404 from a URL that is not a Turso SQL-over-HTTP endpoint; 5xx whose body is an HTML proxy error page, so JSON parsing fails and the fallback text is thrown.","commonSituations":"Expired Turso Cloud platform tokens; wrong or stale database URL after a rename/move; corporate proxies or WAFs returning HTML error pages on auth failure; pointing the client at an older self-hosted server with a different error body.","solutions":["Verify the URL is the database's HTTPS endpoint and re-check the token: curl -i -X POST $URL/v3/pipeline -H \"Authorization: Bearer $TOKEN\" -d '{\"baton\":null,\"requests\":[]}'","Refresh or rotate the token if the status is 401/403","If a proxy intercepts the request, bypass it or fix its error responses so JSON bodies pass through"],"exampleFix":"// before\nconst db = connect({ url: \"https://db.example.com\", authToken: EXPIRED_TOKEN });\nawait db.all(\"SELECT 1\"); // HTTP error! status: 401\n\n// after\nconst token = await refreshPlatformToken();\nconst db = connect({ url: \"https://db.example.com\", authToken: token });\nawait db.all(\"SELECT 1\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isDatabaseError = (e: unknown): e is Error & { code?: string } =>\n  e instanceof Error && e.name === \"DatabaseError\";","tryCatchPattern":"try {\n  await db.all(sql);\n} catch (e) {\n  if (e instanceof Error && /HTTP error! status: (401|403)/.test(e.message)) {\n    // auth problem: refresh the token and reconnect with it\n  } else if (e instanceof Error && /HTTP error! status: 5\\d\\d/.test(e.message)) {\n    // server/proxy problem: check status page, then retry\n  } else throw e;\n}","preventionTips":["Fetch tokens from a fresh source per deploy and rotate before expiry","Keep the database URL in a single env var consumed by one client factory","Smoke-test connectivity at boot with db.all('SELECT 1') so failures surface in health checks"],"tags":["http","authentication","network","javascript"],"backgroundTag":"http-error-status","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}