From f043d8ebb0990f49fd33595edcb1fbf0964566b7 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Mon, 24 Jul 2023 17:34:07 +0100 Subject: [PATCH] Log coral status code --- src/api/coral.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api/coral.ts b/src/api/coral.ts index 5d2f455..94f0bab 100644 --- a/src/api/coral.ts +++ b/src/api/coral.ts @@ -142,14 +142,15 @@ export default class CoralApi implements CoralApiInterface { signal, }).finally(cancel); - debug('fetch %s %s, response %s', method, url, response.status); + const data = await response.json().catch(err => null) as CoralResponse | null; - if (response.status !== 200) { - throw await CoralErrorResponse.fromResponse(response, '[znc] Non-200 status code'); + debug('fetch %s %s, response %s, status %d %s, correlationId %s', method, url, response.status, + data?.status, CoralStatus[data?.status!], data?.correlationId); + + if (response.status !== 200 || !data) { + throw new CoralErrorResponse('[znc] Non-200 status code', response, data as CoralError); } - const data = await response.json() as CoralResponse; - if (data.status === CoralStatus.TOKEN_EXPIRED && _autoRenewToken && !_attempt && this.onTokenExpired) { this._token_expired = true; // _renewToken will be awaited when calling fetch