{"record":{"id":"023f95e01fdc24de","repo":"danny-avila/LibreChat","slug":"failed-to-fetch-url-response-status-response","errorCode":null,"errorMessage":"Failed to fetch URL: ${response.status} ${response.statusText}","messagePattern":"Failed to fetch URL: (.+?) (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/server/services/Files/Azure/crud.js","lineNumber":79,"sourceCode":" * @param {string} [params.basePath='images'] - The base folder within the container.\n * @param {string} [params.containerName] - The Azure Blob container name.\n * @returns {Promise<string>} The URL of the uploaded blob.\n */\nasync function saveURLToAzure({\n  userId,\n  URL,\n  fileName,\n  basePath = defaultBasePath,\n  containerName,\n}) {\n  try {\n    const maxBytes = getRemoteFileFetchMaxBytes();\n    const response = await fetch(assertRemoteFileURL(URL), {\n      timeout: getRemoteFileFetchTimeoutMs(),\n      size: maxBytes,\n    });\n    if (!response.ok) {\n      throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);\n    }\n    assertRemoteFileContentLength(response.headers, maxBytes);\n    const buffer = await response.buffer();\n    if (buffer.length > maxBytes) {\n      throw new Error(`Remote file response too large: ${buffer.length} bytes`);\n    }\n\n    return await saveBufferToAzure({ userId, buffer, fileName, basePath, containerName });\n  } catch (error) {\n    logger.error('[saveURLToAzure] Error uploading file from URL:', error);\n    throw error;\n  }\n}\n\n/**\n * Retrieves a blob URL from Azure Blob Storage.\n *\n * @param {Object} params","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Azure/crud.js#L61-L97","documentation":"Thrown by saveURLToAzure (Azure/crud.js) after fetching a remote file URL via node-fetch when response.ok is false. The fetch is gated by assertRemoteFileURL and carries timeout/size caps; this error surfaces a non-2xx status from the remote origin before any Azure upload is attempted.","triggerScenarios":"POST of a remote URL to the files endpoint resolves to a non-2xx HTTP status (404, 403, 500, etc.) from the origin server, or the origin returns a redirect chain that ends in an error.","commonSituations":"Expired/signed S3 URL passed as an image source; origin requires auth headers not supplied; URL is behind a paywall or geo-blocked; typo in the URL; origin server is down.","solutions":["Verify the URL is publicly reachable with curl -I and returns 2xx.","If the origin needs auth or custom headers, fetch through a proxy that injects them rather than passing the raw URL.","Handle 403/404 distinctly in the caller to give the user an accurate message.","Check that the URL scheme is http/https (assertRemoteFileURL also enforces this)."],"exampleFix":"// before\nconst response = await fetch(assertRemoteFileURL(URL), {...});\nif (!response.ok) {\n  throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);\n}\n\n// after\nconst response = await fetch(assertRemoteFileURL(URL), {...});\nif (!response.ok) {\n  const err = new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);\n  err.statusCode = response.status;\n  throw err;\n}","handlingStrategy":"validation","validationCode":"// HEAD-check the URL before downloading\nconst head = await fetch(assertRemoteFileURL(URL), { method: 'HEAD', timeout: getRemoteFileFetchTimeoutMs() });\nif (!head.ok) {\n  throw new Error(`Preflight failed: ${head.status} ${head.statusText}`);\n}\n// proceed to GET","typeGuard":null,"tryCatchPattern":"try {\n  await saveURLToAzure({ userId, URL, fileName });\n} catch (err) {\n  const m = /^Failed to fetch URL: (\\d{3})/.exec(err.message);\n  if (m) {\n    const status = Number(m[1]);\n    return res.status(status === 404 || status === 403 ? status : 502)\n      .json({ message: `Remote URL returned ${status}` });\n  }\n  throw err;\n}","preventionTips":["Validate URLs are public and return 2xx with a HEAD preflight.","Surface the remote status code to the user instead of a generic 500.","Keep assertRemoteFileURL on the path to block non-http(s) schemes."],"tags":["network","azure","remote-fetch","storage"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}