{"record":{"id":"88dc11f53f8edadf","repo":"gitbutlerapp/gitbutler","slug":"http-error-response-statustext-text","errorCode":null,"errorMessage":"HTTP Error ${response.statusText}: ${text}","messagePattern":"HTTP Error (.+?): (.+?)","errorType":"http","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"packages/shared/src/lib/network/httpClient.ts","lineNumber":120,"sourceCode":"\t\treturn await this.requestJson<T>(path, { ...opts, method: \"DELETE\" });\n\t}\n\n\tasync postRaw(path: string, opts?: RequestOptions) {\n\t\treturn await this.request(path, { ...opts, method: \"POST\" });\n\t}\n}\n\nasync function parseResponseJSON(response: Response) {\n\tif (response.status === 204 || response.status === 205) {\n\t\treturn null;\n\t} else if (response.status === 401) {\n\t\tthrow new ApiError(\"Login token expired. Please log in to GitButler again.\", response);\n\t} else if (response.status >= 400) {\n\t\tconst text = await response.text();\n\t\tif (text.includes(\"401 Unauthorized\") || text.includes(\"401 unauthorized\")) {\n\t\t\tthrow new ApiError(\"Login token expired. Please log in to GitButler again.\", response);\n\t\t}\n\t\tthrow new ApiError(`HTTP Error ${response.statusText}: ${text}`, response);\n\t} else {\n\t\treturn await response.json();\n\t}\n}\n\nfunction formatBody(body?: FormData | object) {\n\tif (!body) return;\n\treturn body instanceof FormData ? body : JSON.stringify(body);\n}\n","sourceCodeStart":102,"sourceCodeEnd":130,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/packages/shared/src/lib/network/httpClient.ts#L102-L130","documentation":"parseResponseJSON throws ApiError(`HTTP Error ${response.statusText}: ${text}`, response) for any response with status >= 400 that is not 401 and whose body does not mention \"401 Unauthorized\". It wraps the raw status text and response body so callers can see exactly what the server rejected.","triggerScenarios":"Any HttpClient get/post/put/patch/delete receiving 4xx/5xx other than 401 — e.g. 404 for a missing project, 422 for validation failures, 500 for backend errors; the message interpolates statusText and the raw body text.","commonSituations":"Requesting a non-existent resource (404); submitting invalid payloads (422); backend outage or bug (500); rate limiting (429); wrong API base URL hitting an unexpected service.","solutions":["Read the interpolated body text in the ApiError message to see the server's actual error explanation","Check response.status on the ApiError: 404 => verify the resource/URL, 422 => fix the payload, 5xx => check backend health/retry","Confirm the API base URL and path are correct for the intended backend version","Add retry/backoff for transient 5xx/429 and surface actionable errors to the UI otherwise"],"exampleFix":"// before\nconst project = await httpClient.get(`projects/${projectId}`);\n// after\ntry {\n  const project = await httpClient.get(`projects/${projectId}`);\n} catch (e) {\n  if (e instanceof ApiError && e.response?.status === 404) {\n    showToast({ message: `Project ${projectId} not found`, style: \"danger\" });\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const url = new URL(path, `${apiUrl}/api/`);\nif (!resourceExists(url)) throw new Error(`Refusing request to unknown resource: ${url}`);","typeGuard":"function isHttpApiError(e: unknown): e is ApiError {\n  return e instanceof ApiError && typeof e.response?.status === 'number' && e.response.status >= 400;\n}","tryCatchPattern":"try {\n  await httpClient.get(path);\n} catch (e) {\n  if (e instanceof ApiError) {\n    const status = e.response?.status;\n    if (status === 404) { /* resource missing */ }\n    else if (status && status >= 500) { /* retry with backoff */ }\n    else { showToast({ message: e.message, style: 'danger' }); }\n  } else { throw e; }\n}","preventionTips":["Validate request payloads before sending to avoid 422s","Branch on ApiError.response.status for specific handling (404/429/5xx)","Add retry with exponential backoff for 5xx and 429","Verify API base URL and endpoint paths against the deployed backend version"],"tags":["http","network","api"],"backgroundTag":"http-error-response","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}