Skip to content

Fix uncaught JSON.parse exception in handleResponse#93

Open
prjanitor wants to merge 1 commit into
digitalfortress-tech:masterfrom
prjanitor:prjanitor/d01badc09fad11dcd0dc6fd788a432b70d3e4d37
Open

Fix uncaught JSON.parse exception in handleResponse#93
prjanitor wants to merge 1 commit into
digitalfortress-tech:masterfrom
prjanitor:prjanitor/d01badc09fad11dcd0dc6fd788a432b70d3e4d37

Conversation

@prjanitor
Copy link
Copy Markdown

Problem

The handleResponse function calls JSON.parse(text) without a try-catch block. If the server returns malformed JSON (e.g., HTML error page, plain text), JSON.parse throws a SyntaxError that is not caught, causing the promise to reject with an unhandled exception.

Solution

Wrap the JSON.parse call in a try-catch block to gracefully handle malformed JSON responses. When parsing fails, data is set to null, allowing the existing error handling logic to continue functioning correctly.

Changes

  • Modified handleResponse in src/fetchWrapper/fetchWrapper.ts
  • Added try-catch around JSON.parse(text) call
  • On parse error, data is set to null instead of throwing an uncaught exception

This PR was generated by PRJanitor — an automated tool that finds and fixes small bugs in open-source projects.

We respect your contribution guidelines — if your project doesn't accept bot PRs, we won't send more. You can also add a .github/prjanitor.yml file with enabled: false to opt out explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant