Log coral status code

This commit is contained in:
Samuel Elliott 2023-07-24 17:34:07 +01:00
parent c7514a0635
commit f043d8ebb0
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6

View File

@ -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<T> | 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<T>;
if (data.status === CoralStatus.TOKEN_EXPIRED && _autoRenewToken && !_attempt && this.onTokenExpired) {
this._token_expired = true;
// _renewToken will be awaited when calling fetch