Skip to content

Commit eee8a5c

Browse files
committed
レスポンスのパースをtry-catchでラップ (#3)
1 parent c3f7b27 commit eee8a5c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/client/Gateway.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ export abstract class Gateway {
9494
? await nodeFetch(url, options)
9595
: await fetch(url, options);
9696

97-
const data = await response.json();
97+
let data;
98+
99+
try {
100+
data = await response.json();
101+
} catch {
102+
// JSONでパースできないレスポンスボディのときはundefinedを返す
103+
data = undefined;
104+
}
98105

99106
if (response.ok) {
100107
return data as T;

0 commit comments

Comments
 (0)