Monday, 13 August 2018

Error-handling to prevent invalid remote API call from crashing Node server?

Hi, I have a project where I set up a Node server to make calls to a remote API and then send the result to the front-end.When the call is for a valid piece of data, it works perfectly. However, when the call is for something not available via the remote API, the entire server ends up crashing. Node prints this to the console:undefined:1 ^ SyntaxError: Unexpected token < in JSON at position 0 I already have alerts set up to inform the user when their request isn't found, but I want them to be able to just continue with sending another request for something different (if they choose to) without the server crashing. Any ideas on how to achieve this?Will I need to have the server restart itself? Or do I need to integrate cluster into this?Thanks!

Submitted August 14, 2018 at 06:48AM by OgunNova

No comments:

Post a Comment