{"record":{"id":"d1962fa2d4f65979","repo":"louislam/uptime-kuma","slug":"onechat-api-error-errormessage","errorCode":null,"errorMessage":"OneChat API Error: ${errorMessage}","messagePattern":"OneChat API Error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/notification-providers/onechat.js","lineNumber":62,"sourceCode":"                const upMessage = {\n                    to: notification.recieverId,\n                    bot_id: notification.botId,\n                    type: \"text\",\n                    message: `UptimeKuma Alert:\n[🟢 Up]\nName: ${monitorJSON[\"name\"]}\n${heartbeatJSON[\"msg\"]}\nTime (${heartbeatJSON[\"timezone\"]}): ${heartbeatJSON[\"localDateTime\"]}`,\n                };\n                await axios.post(url, upMessage, config);\n            }\n\n            return okMsg;\n        } catch (error) {\n            // Handle errors and throw a descriptive message\n            if (error.response) {\n                const errorMessage = error.response.data?.message || \"Unknown API error occurred.\";\n                throw new Error(`OneChat API Error: ${errorMessage}`);\n            } else {\n                this.throwGeneralAxiosError(error);\n            }\n        }\n    }\n}\n\nmodule.exports = OneChat;\n","sourceCodeStart":44,"sourceCodeEnd":71,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/notification-providers/onechat.js#L44-L71","documentation":"OneChat's catch block inspects error.response: if present it throws `OneChat API Error: ${error.response.data?.message || 'Unknown API error occurred.'}`; otherwise it delegates to throwGeneralAxiosError. So this specific message fires only when the OneChat API actually responded (axios rejected with a response) and the body either has a `message` field or not.","triggerScenarios":"POST to the OneChat url returns non-2xx with a JSON body containing message (e.g. invalid token -> 401 with message, rate limit -> 429 with message, bad chat id -> 400), or returns non-2xx with a body lacking `message` (surfaces as 'Unknown API error occurred.').","commonSituations":"OneChat API key/token wrong or expired; recipient chat id invalid; OneChat rate limiting; OneChat API changed its error envelope so data.message is no longer present.","solutions":["Verify the OneChat access token and the chat id / endpoint URL in the notification config.","Log error.response.status and the full error.response.data once to see OneChat's actual error envelope.","If OneChat renamed the field, update the extraction (e.g. data.error or data.detail) to match.","Handle 429 by backing off / reducing notification volume."],"exampleFix":"// before\nconst errorMessage = error.response.data?.message || \"Unknown API error occurred.\";\nthrow new Error(`OneChat API Error: ${errorMessage}`);\n\n// after - include HTTP status and raw body for diagnosability\nconst status = error.response.status;\nconst body = error.response.data;\nconst errorMessage = body?.message || body?.error || JSON.stringify(body);\nthrow new Error(`OneChat API Error (HTTP ${status}): ${errorMessage}`);","handlingStrategy":"try-catch","validationCode":"if (!notification.onechatToken || !notification.onechatUrl) {\n    throw new Error(\"OneChat token and endpoint URL are required\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await axios.post(url, payload, config);\n} catch (error) {\n    if (error.response) {\n        const body = error.response.data;\n        const msg = body?.message || body?.error || JSON.stringify(body);\n        throw new Error(`OneChat API HTTP ${error.response.status}: ${msg}`);\n    }\n    throw new Error(`OneChat transport error: ${error.code || error.message}`);\n}","preventionTips":["Always include HTTP status alongside the API message.","Handle both body.message and alternate error field names defensively.","Distinguish 429 rate limits to apply backoff."],"tags":["network","http","onechat","error-handling","status-code"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}