Skip to content

Commit a68a524

Browse files
jsaraivaelbywan
authored andcommitted
🐛 Update resolver.ts - Add null verification to .get("Content-Type")
The line response.headers.get("Content-Type").split(";")[0] is missing a ? before the call to "split". The Content-Type header may not be filled if the response has no body (e.g., in responses that only return a status code). When that happens, you get the following error: TypeError: Cannot read properties of null (reading 'split') at file://.../node_modules/wretch/dist/resolver.js:44:88 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at <your app's call stack> This verification handles this case.
1 parent a3bec71 commit a68a524

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const resolver = <T, Chain, R>(wretch: T & Wretch<T, Chain, R>) => {
6262
}
6363
return response.text().then((body: string) => {
6464
err.message = body
65-
if (config.errorType === "json" || response.headers.get("Content-Type").split(";")[0] === "application/json") {
65+
if (config.errorType === "json" || response.headers.get("Content-Type")?.split(";")[0] === "application/json") {
6666
try { err.json = JSON.parse(body) } catch (e) { /* ignore */ }
6767
}
6868
err.text = body

0 commit comments

Comments
 (0)