mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-26 22:09:47 +00:00
Log error responses from API when reporting state
This adds the error message from the API to journal logs to better identify those cases where patching to the API fails. Change-type: patch Relates-to: #1680
This commit is contained in:
parent
e745648b5e
commit
2203f78d51
@ -34,8 +34,8 @@ const stateForReport: DeviceStatus = {
|
||||
let reportPending = false;
|
||||
|
||||
class StatusError extends Error {
|
||||
constructor(public statusCode: number) {
|
||||
super();
|
||||
constructor(public statusCode: number, public statusMessage?: string) {
|
||||
super(statusMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,13 +86,13 @@ const sendReportPatch = async (
|
||||
body,
|
||||
};
|
||||
|
||||
const [{ statusCode }] = await request
|
||||
const [{ statusCode, body: statusMessage }] = await request
|
||||
.patchAsync(endpoint, params)
|
||||
.timeout(apiTimeout);
|
||||
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
log.error(`Error from the API: ${statusCode}`);
|
||||
throw new StatusError(statusCode);
|
||||
throw new StatusError(statusCode, JSON.stringify(statusMessage, null, 2));
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user