Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Make sure body was successfully parsed as JSON before filtering #1065

Merged
merged 5 commits into from
Nov 3, 2018

Conversation

winstliu
Copy link
Contributor

@winstliu winstliu commented Jul 2, 2018

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions

Description of the Change

In #1014, package searches were changed to use the atom.io API endpoint rather than calling out through apm. As part of that change, parsing of the resulting JSON data was delegated to the request module. Interestingly, request does not throw an error when it fails to parse the response body as JSON and instead returns the raw body as a string. The new package search code failed to account for this scenario, which resulted in #1052.

Alternate Designs

There are a couple of alternate designs:

  • Manually invoke JSON.parse(), as before
  • Check for the status code
  • Use a combination of the above and a different library, such as window.fetch()

I haven't decided which one to go with yet.

Benefits

Searching should be more resilient to server errors.

Possible Drawbacks

None.

Applicable Issues

Fixes #1052

@bluffed84

This comment has been minimized.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaught TypeError: body.filter is not a function
2 participants