{"record":{"id":"13a005201aa8323d","repo":"transloadit/uppy","slug":"failed-request-with-status-res-status-res-s","errorCode":null,"errorMessage":"Failed request with status: ${res.status}. ${res.statusText}","messagePattern":"Failed request with status: (.+?)\\. (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@uppy/core/src/companion-client/RequestClient.ts","lineNumber":75,"sourceCode":"async function handleJSONResponse<ResJson>(res: Response): Promise<ResJson> {\n  if (res.status === authErrorStatusCode) {\n    throw new AuthError()\n  }\n\n  if (res.ok) {\n    return res.json()\n  }\n\n  let errMsg = `Failed request with status: ${res.status}. ${res.statusText}`\n  let errData: any\n  try {\n    errData = await res.json()\n\n    if (errData.message) errMsg = `${errMsg} message: ${errData.message}`\n    if (errData.requestId) errMsg = `${errMsg} request-Id: ${errData.requestId}`\n  } catch (cause) {\n    // if the response contains invalid JSON, let's ignore the error data\n    throw new Error(errMsg, { cause })\n  }\n\n  if (res.status >= 400 && res.status <= 499 && errData.message) {\n    throw new UserFacingApiError(errData.message)\n  }\n\n  throw new HttpError({ statusCode: res.status, message: errMsg })\n}\n\nfunction emitSocketProgress<M extends Meta, B extends Body>(\n  uploader: { uppy: Uppy<M, B> },\n  progressData: {\n    progress: string // pre-formatted percentage number as a string\n    bytesTotal: number\n    bytesUploaded: number\n  },\n  file: UppyFile<M, B>,\n): void {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/transloadit/uppy/blob/5d4dedd02a1ac0ae022c75c54aca76558f88e256/packages/@uppy/core/src/companion-client/RequestClient.ts#L57-L93","documentation":"This generic Error is thrown from the catch branch of handleJSONResponse: the HTTP request already failed (non-OK status), and additionally the response body could not be parsed as JSON (e.g. an HTML error page from a proxy). The message combines status and statusText, and the original parse failure is attached via { cause }. It exists so callers still get a meaningful error when the server's error body is not JSON.","triggerScenarios":"A RequestClient request returns a non-OK status AND res.json() throws (body is HTML/plain text) — typical for 502/504 gateway errors from nginx, a Companion route served behind a misconfigured proxy, or hitting a non-Companion URL that returns an error page.","commonSituations":"companionUrl points to a wrong path; reverse proxy returns HTML error pages (502 Bad Gateway, Cloudflare challenge); Companion crashed and something else answers; rate-limit pages from CDNs.","solutions":["Inspect the thrown error's status (parse from message) and the cause to see what the body actually was","Fix the companionUrl / proxy configuration so JSON responses (and errors) come from Companion itself","Check the Network tab to see the raw response body for the failing request","If a proxy intercepts errors, configure it to pass through upstream JSON error responses"],"exampleFix":"// before\n// companionUrl misrouted; proxy returns HTML 502 page\nconst data = await companionRequestClient.get('/url') // throws generic Error\n\n// after\nnew Url(uppy, { companionUrl: 'https://companion.example.com' })\n// nginx: proxy_pass http://companion:3020; and avoid custom error_page interception","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await client.get('/url')\n} catch (err) {\n  const status = Number(/status: (\\d+)/.exec(err.message)?.[1])\n  if (status >= 500) { /* gateway issue, retry later */ }\n}","preventionTips":["Configure proxies to pass through upstream JSON errors","Verify companionUrl correctness in every environment","Log err.cause to see what non-JSON body was returned"],"tags":["companion","http","proxy","invalid-json","gateway-error"],"backgroundTag":"http-error-response","analyzedSha":"5d4dedd02a1ac0ae022c75c54aca76558f88e256","analyzedAt":"2026-08-28T12:18:41.267Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}