I have a simple flow (code and sceenshot provided):
- an HTTP Input
- an HTTP request (for which I want to handle errors)
- an HTTP Response (status 200)
- an Catch node along with an HTTP Response (status 500).
What I've noticed is that when an error is thrown from the HTTP Request, although it is caught in the catch node, the flow also continues. Which leads to two HTTP Responses (one with status 200 and one with status 500).
The result is that the client receives a response (500) and when the second one is returned, an error message "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" is logged in Nodered.
Is it possible to break/stop the flow after an error is returned ?
Screenshot
Code:
[{"id":"d0c457e9.3cdf08","type":"tab","label":"Test","disabled":false,"info":""},{"id":"ffd7f970.35e278","type":"http in","z":"d0c457e9.3cdf08","name":"/causeError","url":"/causeError","method":"get","upload":false,"swaggerDoc":"","x":90,"y":160,"wires":[["753bc460.8f534c"]]},{"id":"753bc460.8f534c","type":"http request","z":"d0c457e9.3cdf08","name":"Throw error from failed http request","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://serverdown","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":160,"wires":[["f48a058f.ee0658","97422ab6.d61898"]]},{"id":"f48a058f.ee0658","type":"http response","z":"d0c457e9.3cdf08","name":"Return 200","statusCode":"200","headers":{},"x":650,"y":160,"wires":[]},{"id":"5d87987c.743c68","type":"catch","z":"d0c457e9.3cdf08","name":"Error Handler","scope":["753bc460.8f534c"],"uncaught":false,"x":90,"y":260,"wires":[["1e798ca5.4f13b3","df60da2c.860218"]]},{"id":"df60da2c.860218","type":"http response","z":"d0c457e9.3cdf08","name":"Return 500","statusCode":"500","headers":{},"x":270,"y":260,"wires":[]},{"id":"97422ab6.d61898","type":"debug","z":"d0c457e9.3cdf08","name":"Message from Regular Flow","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":80,"wires":[]},{"id":"1e798ca5.4f13b3","type":"debug","z":"d0c457e9.3cdf08","name":"Message from Error Handler Flow","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":240,"y":340,"wires":[]}]
PS: This is my first post, please provide feedback if the post needs anything else.