You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: