-
Notifications
You must be signed in to change notification settings - Fork 15
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
Unexpected end of JSON input #63
Comments
ok so this is not an issue in this library, i called content.toJson() on an empty response. however i still would argue that the toJson method should get some error handling for such cases. for example if the body is empty return either null or an empty object. but do not crash. |
... just gonna leave this here #50 |
@manciuszz Your problem was that the toJson() is automatically called when you do response.json = () => new Promise((resolve, reject) => {
resolve(response.content.toJSON());
}); Or if you want to do it real proper: response.json = () => new Promise((resolve, reject) => {
try {
const parsedJSON = response.content.toJSON();
resolve(parsedJSON);
} catch (e) {
reject(e);
}
}); That will probably fix it as that returns a promise that still needs to be resolved, while your previous implementation returns a @eikaramba I rather do not change that behavior by default. |
wow super interesting because i struggled with the console.log error myself and it was driving me nuts. so thank you for that explanation. i am not going crazy afterall :) i wasn'T aware that the default nativescript library has the same "problem". so i might aggree with you leaving it like it is and putting the responsibility on the developer to catch this accordingly. one thing could also be to output a console message and informing that the response was not a valid json so that it is clear why this is happening. again, i could see developers doing a simple console.log(response) to check and then wonder why it is not working at all. |
I have created a NativeScript runtime issue about this odd problem: NativeScript/android#1693 |
When i do
and the server responds with an empty body (which is valid for DELETE) and status 204. then i get the above error. it seems this library tries to parse the body no matter what.
Which platform(s) does your issue occur on?
The text was updated successfully, but these errors were encountered: