1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

fix: handle parsing json errors

This commit is contained in:
James Cook 2023-05-09 19:24:03 +01:00
parent 86df2e0927
commit a3e078b0b7
2 changed files with 13 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"classcharts-api": minor
---
Throw more description JSON parsing errors

View file

@ -112,10 +112,14 @@ export class BaseClient {
}
}
const request = await ky(path, requestOptions);
const responseJSON = (await request.json()) as ClassChartsResponse<
unknown,
unknown
>;
let responseJSON: ClassChartsResponse<unknown, unknown>;
try {
responseJSON = await request.json();
} catch (err) {
throw new Error(
"Error parsing JSON. Returned response: " + (await request.text())
);
}
if (responseJSON.success == 0) {
throw new Error(responseJSON.error);
}