# HTTP Request exception handilng problem

**URL:** <https://discourse.nodered.org/t/http-request-exception-handilng-problem/40456>\
**Category:** General\
**Created:** [5 February 2021 19:10 UTC](https://discourse.nodered.org/t/http-request-exception-handilng-problem/40456 "2021-02-05T19:10:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mich3000](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@mich3000](https://discourse.nodered.org/u/mich3000)\
**Post date:** [5 February 2021 19:10 UTC](https://discourse.nodered.org/t/http-request-exception-handilng-problem/40456/1 "2021-02-05T19:10:12Z")

</div>

I just started learning node-red and i am trying to handle exception of HTTP request node.  
When ECONNREFUSED error occurs i try to catch it with CATCH Node.  
Error is catched with CATCH but also next node after HTTP Request is executed.  
What i am doing wrong? Is this normal behavior?  
Thanks

 ![request](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e04cad1d71962e533046dcdd35ee32f4914b639a.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [5 February 2021 19:27 UTC](https://discourse.nodered.org/t/http-request-exception-handilng-problem/40456/2 "2021-02-05T19:27:20Z")

</div>

Hi,

> [@mich3000](#):
>
> Error is catched with CATCH but also next node after HTTP Request is executed

What about using a **Switch node** after your Http request to handle the direction you want your application to take in case of failure.

**Example Flow : (using jsonplaceholder that is a fake API for testing and prototyping)**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c20f88df25d2c99df5e3d702a1075f10a9dc7cd.png)

```auto
[{"id":"aeca6a39.21847","type":"inject","z":"94ab22aa.035ba","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":1480,"wires":[["9d03c4de.3463c"]]},{"id":"9d03c4de.3463c","type":"http request","z":"94ab22aa.035ba","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://jsonplaceholder.typicode.com/users","tls":"","persist":false,"proxy":"","authType":"","x":450,"y":1480,"wires":[["82442f8.50d63d"]]},{"id":"5e5e9f20.b2517","type":"inject","z":"94ab22aa.035ba","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":1600,"wires":[["b492fa76.ade698"]]},{"id":"b492fa76.ade698","type":"http request","z":"94ab22aa.035ba","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://jsonplaceholder.typicode.com/usersxxxx","tls":"","persist":false,"proxy":"","authType":"","x":450,"y":1600,"wires":[["db0c209f.0091b8"]]},{"id":"c40262b6.ef6d98","type":"debug","z":"94ab22aa.035ba","name":"FAIL","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1580,"wires":[]},{"id":"db0c209f.0091b8","type":"switch","z":"94ab22aa.035ba","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"neq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":1600,"wires":[["c40262b6.ef6d98"],["2f9d5c6c.9b9e74"]]},{"id":"2f9d5c6c.9b9e74","type":"debug","z":"94ab22aa.035ba","name":"OK","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1620,"wires":[]},{"id":"3b570afe.df2b06","type":"debug","z":"94ab22aa.035ba","name":"FAIL","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1460,"wires":[]},{"id":"82442f8.50d63d","type":"switch","z":"94ab22aa.035ba","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"neq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":1480,"wires":[["3b570afe.df2b06"],["4b7010de.08bf3"]]},{"id":"4b7010de.08bf3","type":"debug","z":"94ab22aa.035ba","name":"OK","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1500,"wires":[]},{"id":"f33e25d0.55c948","type":"comment","z":"94ab22aa.035ba","name":"URL Exists","info":"","x":440,"y":1440,"wires":[]},{"id":"b93991d0.38cc2","type":"comment","z":"94ab22aa.035ba","name":"URL doesnt Exist","info":"","x":460,"y":1560,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![mich3000](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@mich3000](https://discourse.nodered.org/u/mich3000)\
**Post date:** [5 February 2021 19:56 UTC](https://discourse.nodered.org/t/http-request-exception-handilng-problem/40456/3 "2021-02-05T19:56:42Z")

</div>

Sounds good. Appreciate your help

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 April 2021 19:57 UTC](https://discourse.nodered.org/t/http-request-exception-handilng-problem/40456/4 "2021-04-06T19:57:39Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
