Hi everyone, how are you all doing?
I have a basic flow where a request to an endpoint on the internet is made by an http request node and its response is sent to a http response. I'm forcing a timeout on purpose on that request (by setting msg.requestTimeout to 1ms, to try my error catch functionality.
I have a Catch node listening to "all nodes", which then connects to a change node and then to the http response node, so it returns a formatted response to the requester.
Problem is, when the timeout occurs, the http response node throws a: "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client"
exception, which is caught again by the Catch node, who redirects the exception to the http response again, and so it goes until it hits that exception 9 times. I'd like to avoid that loop on my flow. Could anyone help?
The code to the scenario is here, to help clarify what I'm trying to describe:
[{"id":"9c4c2f99.21c6e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"57104a42.b45f84","type":"http in","z":"9c4c2f99.21c6e","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":160,"y":100,"wires":[["793eb631.aa4418"]]},{"id":"52dca73c.c740a8","type":"http request","z":"9c4c2f99.21c6e","name":"Call external API","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":590,"y":240,"wires":[["8ad6211e.aac7"]]},{"id":"8ad6211e.aac7","type":"http response","z":"9c4c2f99.21c6e","name":"response","statusCode":"","headers":{"content-type":"application/json"},"x":820,"y":340,"wires":[]},{"id":"6a312f65.0d599","type":"catch","z":"9c4c2f99.21c6e","name":"Error Catch","scope":null,"uncaught":false,"x":230,"y":360,"wires":[["d78a3b27.fa12e8"]]},{"id":"793eb631.aa4418","type":"function","z":"9c4c2f99.21c6e","name":"Forcing timeout on a request","func":"msg.url = 'http://viacep.com.br/ws/01001000/json/'\nmsg.method = \"GET\"\nmsg.requestTimeout = 1\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":180,"wires":[["52dca73c.c740a8"]]},{"id":"d78a3b27.fa12e8","type":"change","z":"9c4c2f99.21c6e","name":"Internal Server Error","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.errorType","pt":"msg","to":"INTERNAL_SERVER_ERROR","tot":"str"},{"t":"set","p":"payload.errorCode","pt":"msg","to":"INTERNAL_SERVER_ERROR","tot":"str"},{"t":"set","p":"payload.errorMessage","pt":"msg","to":"An error has ocurred.","tot":"str"},{"t":"set","p":"statusCode","pt":"msg","to":"500","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":360,"wires":[["8ad6211e.aac7"]]}]