Always check response status codes

This commit is contained in:
Samuel Elliott
2022-08-22 11:36:37 +01:00
parent 67819b4af5
commit 624d60dc1b

View File

@@ -42,6 +42,10 @@ export async function getLoginHash(token: string, timestamp: string | number, us
signal,
}).finally(cancel);
if (response.status !== 200) {
throw new ErrorResponse('[s2s] Non-200 status code', response, await response.text());
}
const data = await response.json() as LoginHashApiResponse | LoginHashApiError;
if ('error' in data) {
@@ -87,6 +91,10 @@ export async function flapg(
signal,
}).finally(cancel);
if (response.status !== 200) {
throw new ErrorResponse('[flapg] Non-200 status code', response, await response.text());
}
const data = await response.json() as FlapgApiResponse;
debugFlapg('Got f parameter "%s"', data.result.f);
@@ -160,6 +168,10 @@ export async function iminkf(
signal,
}).finally(cancel);
if (response.status !== 200) {
throw new ErrorResponse('[imink] Non-200 status code', response, await response.text());
}
const data = await response.json() as IminkFResponse | IminkFError;
if ('error' in data) {
@@ -228,6 +240,10 @@ export async function genf(
signal,
}).finally(cancel);
if (response.status !== 200) {
throw new ErrorResponse('[znca-api] Non-200 status code', response, await response.text());
}
const data = await response.json() as AndroidZncaFResponse | AndroidZncaFError;
if ('error' in data) {