{"record":{"id":"c2deaf5dbc3622a4","repo":"chatboxai/chatbox","slug":"status-code-res-status-sanitizeresponsebody","errorCode":null,"errorMessage":"Status Code ${res.status}, ${sanitizeResponseBody(res.status, response)}","messagePattern":"Status Code (.+?), (.+?)","errorType":"http","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"src/shared/request/request.ts","lineNumber":131,"sourceCode":"            },\n          }\n        }\n        const res = await fetch(url, init)\n        // 状态码不在 200～299 之间，一般是接口报错了，这里也需要抛错后重试\n        if (!res.ok) {\n          const response = await res.text().catch((e: unknown) => {\n            console.error('[afetch] Failed to read error response body:', e)\n            return ''\n          })\n          const requestId = getChatboxRequestId(response, res.headers)\n          if (options.parseChatboxRemoteError) {\n            const backendErrorCode = getChatboxErrorCode(response)\n            const chatboxAIError = ChatboxAIAPIError.fromCodeName(response, backendErrorCode || '', requestId)\n            if (chatboxAIError) {\n              throw chatboxAIError\n            }\n          }\n          throw new ApiError(\n            `Status Code ${res.status}, ${sanitizeResponseBody(res.status, response)}`,\n            response || undefined,\n            res.status,\n            requestId\n          )\n        }\n        return res\n      } catch (e) {\n        if (isAbortError(e, init?.signal)) {\n          throw e\n        }\n        if (e instanceof BaseError) {\n          requestError = e\n        } else {\n          const err = toError(e)\n          const origin = getRequestOrigin(url)\n          requestError = new NetworkError(err.message, origin)\n        }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/shared/request/request.ts#L113-L149","documentation":"Error \"Status Code ${res.status}, ${sanitizeResponseBody(res.status, response)}\" thrown in chatboxai/chatbox.","triggerScenarios":"Thrown at src/shared/request/request.ts:131 when the library encounters an invalid state.","commonSituations":"Occurs in src/shared/request/request.ts when an API request returns a non-success HTTP status and the response body is sanitized and thrown.","solutions":["Read the sanitized response body included in the error for the upstream error message.","For 401/403, check API key or token validity; for 429, back off and retry later.","For 5xx, retry the request; afetch already retries with 500ms delay for retryable failures.","Verify the request URL and payload against the API documentation."],"exampleFix":"if (!res.ok) {\n  const response = await res.text()\n  // Log status + body, then decide: fix auth, reduce rate, or correct the payload\n}","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}