Skip to content

Commit a06f092

Browse files
committed
Gracefully handle JSON parse error
1 parent 7f151d5 commit a06f092

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib/boosthub.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ function useBoostHubStore() {
5656
method: 'get',
5757
...options,
5858
}
59-
return webviewRef.current!.executeJavaScript(
60-
`fetch("${url}", {method: "${method}"}).then(response => response.json())`
59+
const rawText = await webviewRef.current!.executeJavaScript(
60+
`fetch("${url}", {method: "${method}"}).then(response => response.text())`
6161
)
62+
try {
63+
return JSON.parse(rawText)
64+
} catch (error) {
65+
console.warn('Invalid json body', error)
66+
throw new Error(rawText)
67+
}
6268
},
6369
[]
6470
)

0 commit comments

Comments
 (0)