From 624d60dc1bdb8de29314234001b0f023b7911ca4 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Mon, 22 Aug 2022 11:36:37 +0100 Subject: [PATCH] Always check response status codes --- src/api/f.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/api/f.ts b/src/api/f.ts index 59c85dc..18f3bd8 100644 --- a/src/api/f.ts +++ b/src/api/f.ts @@ -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) {