Skip to content

Commit

Permalink
Fix empty response on fetch
Browse files Browse the repository at this point in the history
Check the status code (204 means no content) and the content type to know if we can safely call 'response.json()'
  • Loading branch information
lmignon committed Dec 14, 2023
1 parent 90afd45 commit 0e61fff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ErpFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export class ErpFetch {
} else if (responseType === 'arrayBuffer') {
return response.arrayBuffer()
} else if (responseType === 'json') {
return response.json()
if (response.status === 204) {
// empty response
return null;
} else {
return response.json();
}
} else {
return response;
}
Expand Down

0 comments on commit 0e61fff

Please sign in to comment.