{"record":{"id":"8fcaa232ff927fba","repo":"tursodatabase/turso","slug":"http-request-failed-e-instanceof-error-e-mess","errorCode":null,"errorMessage":"HTTP request failed: ${e instanceof Error ? e.message : String(e)}. URL: ${fullUrl}, Method: ${request.method}, Body size: ${request.body ? request.body.byteLength : 0} bytes","messagePattern":"HTTP request failed: (.+?)\\. URL: (.+?), Method: (.+?), Body size: (.+?) bytes","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"bindings/react-native/src/internal/ioProcessor.ts","lineNumber":217,"sourceCode":"  let response;\n  try {\n    response = await fetch(fullUrl, options);\n  } catch (e) {\n    // Detailed error logging\n    const errorDetails = {\n      url: fullUrl,\n      method: request.method,\n      hasBody: !!request.body,\n      bodySize: request.body ? request.body.byteLength : 0,\n      bodyType: request.body ? Object.prototype.toString.call(options.body) : 'none',\n      error: e instanceof Error ? {\n        message: e.message,\n        name: e.name,\n        stack: e.stack,\n      } : String(e),\n    };\n    console.error('[Turso HTTP] Request failed:', JSON.stringify(errorDetails, null, 2));\n    throw new Error(`HTTP request failed: ${e instanceof Error ? e.message : String(e)}. URL: ${fullUrl}, Method: ${request.method}, Body size: ${request.body ? request.body.byteLength : 0} bytes`);\n  }\n\n\n  // Set status code\n  item.setStatus(response.status);\n\n  // Read response body and push to item\n  const responseData = await response.arrayBuffer();\n  if (responseData.byteLength > 0) {\n    item.pushBuffer(responseData);\n  }\n\n  // Mark as done\n  item.done();\n}\n\n/**\n * Process a full read request (atomic file read)","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/react-native/src/internal/ioProcessor.ts#L199-L235","documentation":"processHttpRequest() executes sync IO with fetch(); if fetch itself throws (network-level failure), the catch logs structured details via console.error ('[Turso HTTP] Request failed:') and rethrows this wrapper including the underlying message, URL, method, and body size. Note that HTTP error statuses are NOT this error — response.status is delivered to the engine via item.setStatus(); this throw means the request never completed.","triggerScenarios":"Device offline or DNS resolution failing while a query triggers remote page fetches; TLS handshake rejected (self-signed or expired cert); connection refused/reset mid-request (server restart, network switch); a misbehaving proxy or firewall in React Native's fetch layer.","commonSituations":"Mobile apps losing connectivity mid-operation; Android emulators with broken DNS; corporate networks MITMing TLS; airplane-mode toggles during a sync; the RN debugger's fetch polyfill behaving differently.","solutions":["Check the logged error name/message first — 'Network request failed' means transport-level failure, cert errors mention TLS","Verify the URL is reachable from the device (not just your laptop) and the scheme survives normalizeUrl (libsql:// is mapped to https://)","Add retry with backoff around operations that can trigger remote IO, treating transient offline windows as expected","For TLS issues, ensure a valid certificate chain or configure appropriate trust in the native network stack"],"exampleFix":"// before\nconst rows = await stmt.all(); // throws: HTTP request failed: Network request failed. URL: https://..., Method: POST, ...\n\n// after\nasync function withNetworkRetry<T>(fn: () => Promise<T>, tries = 3): Promise<T> {\n  for (let i = 0; ; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (i < tries - 1 && /HTTP request failed/.test(String(e.message))) {\n        await new Promise(r => setTimeout(r, 200 * (i + 1)));\n        continue;\n      }\n      throw e;\n    }\n  }\n}\nconst rows = await withNetworkRetry(() => stmt.all());","handlingStrategy":"retry","validationCode":"async function canReach(url: string): Promise<boolean> {\n  try {\n    const res = await fetch(url, { method: 'HEAD' });\n    return res.status < 500 || res.status >= 200; // transport worked\n  } catch {\n    return false;\n  }\n}\n// gate operations that trigger remote IO\nif (!(await canReach(syncUrl))) throw new Error('sync endpoint unreachable');","typeGuard":"function isHttpRequestFailed(e: unknown): boolean {\n  return e instanceof Error && e.message.startsWith('HTTP request failed');\n}","tryCatchPattern":"async function runWithRetry<T>(fn: () => Promise<T>, tries = 3): Promise<T> {\n  for (let i = 0; ; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (i < tries - 1 && isHttpRequestFailed(e)) {\n        await new Promise(r => setTimeout(r, 250 * 2 ** i)); // exponential backoff\n        continue;\n      }\n      throw e;\n    }\n  }\n}\nconst rows = await runWithRetry(() => stmt.all());","preventionTips":["Expect offline windows on mobile: wrap remote-IO-triggering operations in bounded retry with backoff","Read the '[Turso HTTP] Request failed' log for error.name — Network request failed vs. TLS tells you the fix","Verify device-level reachability of the sync host (emulator DNS and proxies differ from your laptop)","Distinguish this transport failure from HTTP status errors, which the engine handles via setStatus"],"tags":["network","http","fetch","react-native","sync"],"backgroundTag":"http-request-failed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}