We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 309b11f commit 1a4d0adCopy full SHA for 1a4d0ad
packages/error/index.js
@@ -40,12 +40,21 @@ export class IndiekitError extends Error {
40
}
41
42
static async fromFetch(response) {
43
- const body = await response.json();
44
- const message = body.error_description || response.statusText;
+ let body;
+ let message = response.statusText;
45
+
46
+ try {
47
+ // Parse JSON response, if provided
48
+ body = await response.json();
49
+ message = body.error_description || response.statusText;
50
+ } catch (error) {
51
+ console.error(error);
52
+ }
53
54
return new IndiekitError(message, {
55
status: response.status,
- code: body.error || response.statusText,
- cause: body.cause,
56
+ code: body?.error || response.statusText,
57
+ cause: body?.cause,
58
});
59
60
0 commit comments