{"record":{"id":"5cbfb6fe309d1217","repo":"pot-app/pot-desktop","slug":"http-request-error-http-status-response-status","errorCode":null,"errorMessage":"Http Request Error\nHttp Status: ${response.status}\n${await response.text()}","messagePattern":"Http Request Error\nHttp Status: (.+?)\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/translate/chatglm/index.jsx","lineNumber":58,"sourceCode":"\n    const body = {\n        model: model,\n        messages: promptList,\n        stream: true,\n        thinking: {\n            type: \"disabled\",\n        }\n    };\n\n    let result = '';\n    try {\n        const response = await fetch('https://open.bigmodel.cn/api/paas/v4/chat/completions', {\n            method: 'POST',\n            headers: headers,\n            body: JSON.stringify(body),\n        });\n        if (!response.ok) {\n            throw new Error(`Http Request Error\\nHttp Status: ${response.status}\\n${await response.text()}`);\n        }\n\n        let buffer = '';\n        // Function to process the stream data\n        const processChatStream = async (reader, decoder) => {\n            while (true) {\n                const { done, value } = await reader.read();\n                if (done) break;\n\n                // Convert binary data to string\n                buffer += decoder.decode(value, { stream: true });\n                \n                // Process complete events\n                const boundary = buffer.lastIndexOf('\\n\\n');\n                if (boundary !== -1) {\n                    const event = buffer.slice(0, boundary);\n                    buffer = buffer.slice(boundary + 2);\n                    const chunks = event.split('\\n\\n');","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/pot-app/pot-desktop/blob/594d32ede96acd106b0256deaa8bb440ffcdff40/src/services/translate/chatglm/index.jsx#L40-L76","documentation":"The ChatGLM (open.bigmodel.cn) translate service throws this when the POST to the chat/completions API returns a non-2xx status. It includes the status and the response body (which usually contains a JSON error object with code/message from the GLM API) so the developer can see the API-level failure reason.","triggerScenarios":"Calling the ChatGLM translate flow when the POST https://open.bigmodel.cn/api/paas/v4/chat/completions fails: invalid/expired API key (401), insufficient balance/quota (429 or 4xx with quota code), malformed request body, or model name not available to the account.","commonSituations":"User pasted a wrong or revoked API key into the ChatGLM config, the account ran out of tokens/credits, the API key was regenerated server-side, or the chosen model (e.g. glm-4) was deprecated or not entitled for the key.","solutions":["Read the JSON body in the message — the `code`/`message` fields from bigmodel.cn identify the exact cause (1002/1113 auth issues, 1301 quota, etc.).","Verify the API key in the ChatGLM service config; regenerate it at open.bigmodel.cn if expired.","Check account balance/quota on the bigmodel.cn console and top up if exhausted.","Confirm the model name in the request body is one your key can access."],"exampleFix":"// before\nif (!response.ok) {\n    throw new Error(`Http Request Error\\nHttp Status: ${response.status}\\n${await response.text()}`);\n}\n// after\nif (response.status === 401) {\n    throw new Error('ChatGLM API key invalid or expired — update it in settings');\n}\nif (!response.ok) {\n    throw new Error(`Http Request Error\\nHttp Status: ${response.status}\\n${await response.text()}`);\n}","handlingStrategy":"try-catch","validationCode":"function validateChatGLMConfig(config) {\n  return typeof config.apiKey === 'string' && config.apiKey.trim().length > 0 && /^([a-zA-Z0-9]+\\.)?[a-zA-Z0-9]{16,}$/.test(config.apiKey.trim());\n}\n// call before issuing the request; also check navigator.onLine","typeGuard":"function isGlmErrorResponse(body) {\n  return body != null && typeof body === 'object' && typeof body.code !== 'undefined' && typeof body.message === 'string';\n}","tryCatchPattern":"try {\n  const result = await chatglmTranslate(text, from, to);\n} catch (e) {\n  const msg = String(e.message);\n  if (msg.includes(' 401') || msg.includes('1002') || msg.includes('1113')) {\n    promptUserToFixApiKey(); // invalid/expired key\n  } else if (msg.includes('1301') || msg.includes(' 429')) {\n    promptUserToTopUpOrWait(); // quota/rate limit\n  } else {\n    throw e;\n  }\n}","preventionTips":["Validate the API key format in settings before saving the service config","Monitor bigmodel.cn balance/quota and top up proactively","Regenerate the key after any suspected leak; update it in config immediately","Keep the model name in sync with what your account tier supports"],"tags":["network","api-key","llm","chatglm"],"backgroundTag":"http-non-2xx-response","analyzedSha":"594d32ede96acd106b0256deaa8bb440ffcdff40","analyzedAt":"2026-09-02T18:12:21.811Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}