mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-22 04:18:10 +00:00
Merge pull request #1692 from balena-os/1680-cloud-responses
Log error responses from API when reporting state
This commit is contained in:
commit
537beae17b
@ -34,8 +34,8 @@ const stateForReport: DeviceStatus = {
|
|||||||
let reportPending = false;
|
let reportPending = false;
|
||||||
|
|
||||||
class StatusError extends Error {
|
class StatusError extends Error {
|
||||||
constructor(public statusCode: number) {
|
constructor(public statusCode: number, public statusMessage?: string) {
|
||||||
super();
|
super(statusMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +86,13 @@ const sendReportPatch = async (
|
|||||||
body,
|
body,
|
||||||
};
|
};
|
||||||
|
|
||||||
const [{ statusCode }] = await request
|
const [{ statusCode, body: statusMessage }] = await request
|
||||||
.patchAsync(endpoint, params)
|
.patchAsync(endpoint, params)
|
||||||
.timeout(apiTimeout);
|
.timeout(apiTimeout);
|
||||||
|
|
||||||
if (statusCode < 200 || statusCode >= 300) {
|
if (statusCode < 200 || statusCode >= 300) {
|
||||||
log.error(`Error from the API: ${statusCode}`);
|
log.error(`Error from the API: ${statusCode}`);
|
||||||
throw new StatusError(statusCode);
|
throw new StatusError(statusCode, JSON.stringify(statusMessage, null, 2));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user