-
Notifications
You must be signed in to change notification settings - Fork 298
JSON.parse(data) errors #1000
Comments
@KrishnaPG would you be willing to submit a PR for the This would also resolve #912 |
Thank you. I am not sure if Without
With
The code that produced the above errors:
|
Good point, I think we should iterate on #1001. "Invalid JSON" is the correct message here and having the data in the message is useful. The problem is with the error handling code: It uses We should pass In Does that make sense? |
Interesting. So the whole thing is already inside an error handling mechanism ( |
Added the
In case, there is no valid textual message from the stream, the above error will look as below:
And in case of the JSON parsing errors, the error will continue to have the format: Looks like this covers the JSON parsing error with data + non-json error messages scenarios. Combined both commits into the same PR: #1001 |
Making the `parseError` function compatible with non-JSON responses from server. - `isJson = true` parameter added that is backwards compatible with existing code Ref: #1000 (comment)
It looks like the IPFS gateways return plain text errors, while the clients are expecting JSON, which is causing the json.parse to throw errors many times, (such as
404 not found
,method not allowed
etc.)The problem is, while the
json.parse
line 27 throws the error it discards the original data, leaving caller have no clue why the parse failed.For example, here is one error received on the client side returned by IPFS deamon: if you put a breakpoint and observe the data, it has some valuable information such as:
argument "key" is required
, which gets lost when the exception is thrown at line 27The rethrown error at the call site contains stack with incorrect (and useless) error message:
Suggestion:
or something like
return cb(new Error("Invalid JSON: ${data}"))
For beginners, being able to understand the server errors is very important, since it is not always possible get things right the first time.
The text was updated successfully, but these errors were encountered: