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

Error: "Unable to parse response body into JSON: 10 #2

Closed
robtesch opened this issue Apr 11, 2019 · 5 comments
Closed

Error: "Unable to parse response body into JSON: 10 #2

robtesch opened this issue Apr 11, 2019 · 5 comments

Comments

@robtesch
Copy link

robtesch commented Apr 11, 2019

Hi Lanlin,

I've hit a new issue, as described in the title. This is only happening on one account. If possible, would there be a way of simply ignoring if this error occurs on a single message, and move on to all the others? I have a feeling that for a single message the JSON is corrupt or something.

Thanks,

Rob

@lanlin
Copy link
Owner

lanlin commented Apr 11, 2019

I think it‘s nothing about json_decode, but the data responded from Nylas was invalid JSON.

In Nylas's API docs, they said:
image

I have checked the content type from the response header, like this:
image

So, when it's not JSON, it will be returned directly without parsing.

And, "Unable to parse response body into JSON: 10" means that:
the "JSON_ERROR_UTF16" error occurs.

The reason is single unpaired UTF-16 surrogate in Unicode escape contained in the JSON string passed to json_encode().

I will add a new config option which can be used to control the exception throws when decoding the responded body.

After it enabled, the body content will be returned directly without parsing when the json_decode error occurs.

@lanlin
Copy link
Owner

lanlin commented Apr 11, 2019

@robtesch
Copy link
Author

@lanlin awesome! Thank you! Will give it a go ASAP and let you know (probably only on Sunday).

@robtesch
Copy link
Author

@lanlin OK fantastic, I managed to use this config option to work around the issue of the invalid json response from nylas. Turns out it was only 1 message from 1 account that was causing the issue. I have now built a workaround where I simply request smaller and smaller batches of messages until I get only valid messages, then I increment the offset to skip the invalid message.

@lanlin
Copy link
Owner

lanlin commented Apr 12, 2019

@robtesch That's good.

@lanlin lanlin closed this as completed Apr 12, 2019
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

No branches or pull requests

2 participants