diff --git a/src/lib/utils/api.ts b/src/lib/utils/api.ts index 7f9c116c9..d6a4d03d2 100644 --- a/src/lib/utils/api.ts +++ b/src/lib/utils/api.ts @@ -40,11 +40,22 @@ export async function getApiResponse( } if (isErrorCode(resp.status)) { - response.error = { - status: resp.status, - message: resp.statusText, - errors: resp.json ? await resp.json() : null, - }; + try { + response.error = { + status: resp.status, + message: resp.statusText, + errors: resp.json ? await resp.json() : null, + }; + } catch (error) { + console.error(error); + // if we fail parsing the error's JSON, + // just return the status + response.error = { + status: resp.status, + message: resp.statusText, + errors: null, + }; + } return response; }