From 2203f78d517a9edf75a261dd3c77cdf5b609548c Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 3 May 2021 18:08:24 +0000 Subject: [PATCH] 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 --- src/device-state/current-state.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/device-state/current-state.ts b/src/device-state/current-state.ts index 39edd5eb..b9d828e6 100644 --- a/src/device-state/current-state.ts +++ b/src/device-state/current-state.ts @@ -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)); } };