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
5
.changeset/modern-rabbits-film.md
Normal file
5
.changeset/modern-rabbits-film.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"classcharts-api": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Throw more description JSON parsing errors
|
||||||
|
|
@ -112,10 +112,14 @@ export class BaseClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const request = await ky(path, requestOptions);
|
const request = await ky(path, requestOptions);
|
||||||
const responseJSON = (await request.json()) as ClassChartsResponse<
|
let responseJSON: ClassChartsResponse<unknown, unknown>;
|
||||||
unknown,
|
try {
|
||||||
unknown
|
responseJSON = await request.json();
|
||||||
>;
|
} catch (err) {
|
||||||
|
throw new Error(
|
||||||
|
"Error parsing JSON. Returned response: " + (await request.text())
|
||||||
|
);
|
||||||
|
}
|
||||||
if (responseJSON.success == 0) {
|
if (responseJSON.success == 0) {
|
||||||
throw new Error(responseJSON.error);
|
throw new Error(responseJSON.error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue