-
Notifications
You must be signed in to change notification settings - Fork 1k
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
bug: [CapacitorHttp] error parsing certain JSON responses #6170
Comments
I just checked it on Android as well. There the result is also a generic message capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java Lines 297 to 318 in f4e7f19
|
@JanMisker : happening as well in my code. "Real" fetch works correctly, but the patched fetch fails on anything that isn't a JSON array or object pretty much. I realize replacing "fetch" seamlessly is a Herculean task. But the number of bugs in this feature is staggering. |
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue. Please see the Contributing Guide for how to create a Code Reproduction. Thanks! |
This comment was marked as abuse.
This comment was marked as abuse.
@JanMisker : I tried to work around this issue by calling As for this part:
It is valid JSON, see https://www.json.org/json-en.html, so it's part of the spec. |
@silviogutierrez nice to see you're also busy with it. I also made this mock response that outputs the JSON string |
@JanMisker : looks like for iOS, I can't find an equivalent built-in method for Java, but maybe it exists. I also don't know if there's a reason why the JSON is parsed manually. Maybe something to do with the bridge. Chesterton's fence and all. What I'm doing now is patching both those codebases to just return a string. Then in my own app I just use In fact, you could just manually instantiate |
I created a repository to reproduce the error https://github.com/JanMisker/Capacitor-JSONParseError |
And here is a PR #6224 |
I have the same problem, the used api endpoint just returns an integer value (e.g. Will this be fixed at some point? This prevents you from using CapacitorHttp for a public api where you have no influence on the return value. |
It's really a pity that there seems to be no interest from the Ionic team, even though this is a core/official plugin. |
You've got a PR up? Thanks! I'll take a look. |
Fixed in #6224 |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out. |
Bug Report
Capacitor Version
Platform(s)
Checked it only on iOS for now.
Current Behavior
I have the CapacitorHttp plugin enabled.
The following response body is not parsed as JSON but instead returns the string
The data couldn’t be read because it isn’t in the correct format.
I suppose it is debatable whether this is valid JSON, it's of course not an object but a string.
However the generic failure message feels a bit too much like a "bail out".
Expected Behavior
Replacing the string
The data couldn’t be read because it isn’t in the correct format.
with the actual text of the response data would help a lot.This can easily be achieved by replacing
return error.localizedDescription
withreturn String(data: data, encoding: .utf8)
, maybe with another check to remove the"
quotes.capacitor/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift
Lines 32 to 38 in f4e7f19
Code Reproduction
Bit tricky to make a repo, as it depends on the server output.
Other Technical Details
Additional Context
The text was updated successfully, but these errors were encountered: