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:
parent
86df2e0927
commit
a3e078b0b7
2 changed files with 13 additions and 4 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue