Always check response status codes

This commit is contained in:
Samuel Elliott
2022-08-13 01:31:16 +01:00
parent 0697504379
commit 77f07eb1b3
5 changed files with 11 additions and 3 deletions

View File

@@ -56,6 +56,10 @@ export default class CoralApi {
debug('fetch %s %s, response %s', method, url, response.status);
if (response.status !== 200) {
throw new ErrorResponse('[znc] Non-200 status code', response, await response.text());
}
const data = await response.json() as CoralResponse<T>;
if (data.status === CoralStatus.TOKEN_EXPIRED && _autoRenewToken && !_attempt && this.onTokenExpired) {

View File

@@ -49,6 +49,10 @@ export default class MoonApi {
debug('fetch %s %s, response %s', method, url, response.status);
if (response.status !== 200) {
throw new ErrorResponse('[moon] Non-200 status code', response, await response.text());
}
const data = await response.json() as T | MoonError;
if ('errorCode' in data) {

View File

@@ -45,7 +45,7 @@ export default class NooklinkApi {
debug('fetch %s %s, response %s', method, url, response.status);
if (response.status !== 200 && response.status !== 201) {
throw new ErrorResponse('[nooklink] Unknown error', response, await response.text());
throw new ErrorResponse('[nooklink] Non-200/201 status code', response, await response.text());
}
const data = await response.json() as T | WebServiceError;

View File

@@ -53,7 +53,7 @@ export default class SplatNet2Api {
debug('fetch %s %s, response %s', method, url, response.status);
if (response.status !== 200) {
throw new ErrorResponse('[splatnet2] Unknown error', response, await response.text());
throw new ErrorResponse('[splatnet2] Non-200 status code', response, await response.text());
}
updateIksmSessionLastUsed.handler?.call(null, this.iksm_session);

View File

@@ -44,7 +44,7 @@ export default class ZncProxyApi implements CoralApi {
if (response.status === 204) return null!;
if (response.status !== 200) {
throw new ErrorResponse('[zncproxy] Unknown error', response, await response.text());
throw new ErrorResponse('[zncproxy] Non-200/204 status code', response, await response.text());
}
const data = await response.json() as T;