Skip to content

Make the malformed response error message debuggable #4177

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

Merged
merged 3 commits into from
Sep 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Controllers/HooksController.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ function wrapToHTTPRequest(hook, key) {
try {
body = JSON.parse(body);
} catch (e) {
err = { error: "Malformed response", code: -1 };
err = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the e: SyntaxError have any useful info?

think this is worth unit testing??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case i'm trying to cover here isn't actually bad JSON it's when you don't have JSON at all and the text reads "Socket closed because not https" or something like that. We could also provide the e.toString() or e.message though for when there is a problem with the json formatting (but I think that is much less common since these are usually machine serialized results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely useful but feels sloppy, any other ideas on how to make this better @acinader?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't over think it. adds good feedback on an error. I approved it cause I think it's mergeable.

error: "Malformed response",
code: -1,
partialResponse: body.substring(0, 100)
};
}
}
if (!err) {
Expand Down