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

src/request.js is not passing any metadata about result to the callback #39

Open
crianonim opened this issue Aug 2, 2019 · 0 comments
Assignees

Comments

@crianonim
Copy link

Your https request function is always passing the JSON.parsed response text from the call.
If there is a problem with your request (404, 500, or any other) this information is not passed in any way to the callback, you assume your request will always work perfectly (happy path) and will always receive JSON, therefore no way to handle errors. You do handle errors ( on('error') ) but these errors are only related to the transmission between the server and api server. If the api server responds (ie with 404 status code and 'Not found' text) then error won't be triggered.
Also if the response for any reason is not a correct JSON, it will throw an error and break.

Suggested ways to resolve it:
Send an object with minimum of properties { statusCode, body}

and if you care about JSON not throwing an error, wrap it in try catch.

@jackbridger jackbridger self-assigned this Aug 2, 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