Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESO-2736: Improve error handling with non-JSON response bodies #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ntwiles
Copy link

@ntwiles ntwiles commented Dec 26, 2023

Two errors were mentioned in the original ticket.

  • Cannot read property 'statusCode' of undefined. This is caused on line 33 by trying to read statusCode from a res which might be undefined (it will be in the case that err is truthy), since that's an error thrown locally before a request is made, and so there will be no response. The fix here is applied on line 33.

  • Unexpected token < in JSON at position 1 at JSON.parse. This one is more apparent; the body in some cases us html and thus not JSON parsable. I applied a function to try to parse and to just replace with undefined if the parse fails. I don't love this solution and I'm very open to others. I assume error only happens in the case of non-200 status responses, but I applied the change for the success branch (the last if-else chain item) also just in case.

@ntwiles ntwiles changed the title RESO-2736: Add fix and test. RESO-2736: Improve error handling with non-JSON response bodies Jan 3, 2024
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