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

Don't process response body for http status 204 (no content) #7301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jwltr
Copy link

@jwltr jwltr commented Feb 29, 2024

The web implementation of the http plugin tries to parse all successful responses, including responses with status 204 - no content. If the responseType is 'json' and the response status is 204 with no body, parsing the response with response.json() results in the exception "SyntaxError: Unexpected end of JSON input".
This is unexpected, the absence of a response body should not cause an exception if the status code is 204, as the 204 indicates that no body is present.

The ios and Android implementations of the http plugin behave differently in such a case, the Android implementation sets data to an empty string, the ios implementation to "The data couldn't be read because it isn't in the correct format.". They actually never throw an exception, on Android data is set to the input string, on ios to the aforementioned error string.

This pull requests adjusts the web implementation to the Android implementation: if parsing fails, data is set to the input string instead of throwing an exception. On a 204 response with no body, data is set to an empty string.

Same issue in an earlier capacitor version: #6628

@jwltr jwltr marked this pull request as ready for review March 5, 2024 16:23
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.

None yet

1 participant