Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens fbgraph’s HTTP response handling by preventing unhandled exceptions when parsing response bodies as JSON, and adds a regression test to ensure malformed JSON doesn’t crash the client.
Changes:
- Wrap
JSON.parseinGraph.prototype.get/postwithtry/catchto avoid crashing on invalid JSON. - Check for image responses before attempting JSON parsing in
get. - Add a Vows test that stubs
request.getto return malformed JSON and asserts an error is returned.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
lib/graph.js |
Adds defensive try/catch around JSON parsing in get/post and reorders image detection to avoid parsing binary/image responses. |
tests/graph.test.js |
Adds a new batch that stubs request.get to validate malformed JSON is surfaced as an error instead of throwing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
andrewgazda
approved these changes
Mar 19, 2026
| var callback = this.callback | ||
| , originalGet = request.get; | ||
|
|
||
| request.get = function (options, cb) { |
There was a problem hiding this comment.
do we need to somehow reset this back to what it was?
Author
There was a problem hiding this comment.
I believe that's line 296 below
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the robustness of JSON parsing in the
Graphclass by adding error handling for malformed JSON responses. It also introduces new tests to verify that the application handles non-JSON responses gracefully instead of crashing.Error handling improvements:
Graph.prototype.getandGraph.prototype.postinlib/graph.jsto wrap JSON parsing in atry/catchblock, ensuring that parsing errors do not crash the application and that raw bodies are passed toend()if parsing fails. [1] [2]Testing enhancements:
tests/graph.test.jsto simulate receiving a malformed JSON response and verify that the error is handled correctly, returning an error instead of crashing.requestmodule intests/graph.test.jsto enable mocking of HTTP requests for the new tests.