Prevent close event for node.js spawn when spawned process throws an error

I have a nodejs server that starts a python script with spawn.

There are checks in the python script that can throw an error, and it’s actually expected to have those error checks and returned to the server.

But when an error is thrown, the close event in node is eventually triggered and the nodejs server stops altogether.

I cannot seem to figure out how to prevent the spawned process from exiting and closing the server (just accepting and treating the error from the python script). Can someone guide me there?

Or should I maybe restart the server each time?

Read more here: Source link