Merge pull request #1692 from balena-os/1680-cloud-responses

Log error responses from API when reporting state
This commit is contained in:
bulldozer-balena[bot] 2021-05-06 00:04:37 +00:00 committed by GitHub
commit 537beae17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));
} }
}; };