# How to catch 1 error many times

**URL:** <https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753>\
**Category:** General\
**Created:** [10 February 2021 15:40 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753 "2021-02-10T15:40:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [10 February 2021 15:40 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/1 "2021-02-10T15:40:20Z")

</div>

Hi,

I send the file using `ftp` (_node-red-contrib-ftp_) node, in case the sending fails, I want to resend with the specified number of times.  
If the specified number of times fails to send the file, the error message will be displayed.

I have tried to execute with the flow as below, the error "_Message exceeded maximum number of catches_" has occurred, indicates that the `catch` node has an internal fail-safe to prevent endless loops.

```auto
[{"id":"253f62e9.8c881e","type":"tab","label":"Catch FTP","disabled":false,"info":""},{"id":"958f10a1.7f7","type":"inject","z":"253f62e9.8c881e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":290,"y":180,"wires":[["faeb86e6.459f98"]]},{"id":"faeb86e6.459f98","type":"change","z":"253f62e9.8c881e","name":"","rules":[{"t":"set","p":"count","pt":"global","to":"15","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":180,"wires":[["102beac8.b0b405"]]},{"id":"b327d5f9.4a55f8","type":"catch","z":"253f62e9.8c881e","name":"catch [ftp] node","scope":["36599409.788abc"],"uncaught":false,"x":300,"y":360,"wires":[["46bbcb02.5fae34"]]},{"id":"36599409.788abc","type":"ftp in","z":"253f62e9.8c881e","ftp":"5c57a739.a7bd48","operation":"put","filename":"Test.ini","localFilename":"C:\\Temp\\Test.ini","name":"","x":890,"y":180,"wires":[[]]},{"id":"102beac8.b0b405","type":"change","z":"253f62e9.8c881e","name":"i = 0","rules":[{"t":"set","p":"i","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":180,"wires":[["36599409.788abc"]]},{"id":"46bbcb02.5fae34","type":"switch","z":"253f62e9.8c881e","name":"msg.i = global.count ?","property":"i","propertyType":"msg","rules":[{"t":"eq","v":"count","vt":"global"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":520,"y":360,"wires":[["6d3c581.f0c04a8"],["6d420ea5.2cb2c"]]},{"id":"6d420ea5.2cb2c","type":"change","z":"253f62e9.8c881e","name":"i++","rules":[{"t":"set","p":"i","pt":"msg","to":"$.i + 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":300,"wires":[["36599409.788abc","c349acc5.5986d"]]},{"id":"13e0fbb5.197cc4","type":"debug","z":"253f62e9.8c881e","name":"Failed to send file!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":420,"wires":[]},{"id":"6d3c581.f0c04a8","type":"change","z":"253f62e9.8c881e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Failed to send file!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":420,"wires":[["13e0fbb5.197cc4"]]},{"id":"c349acc5.5986d","type":"debug","z":"253f62e9.8c881e","name":"i","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"i","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":300,"wires":[]},{"id":"5c57a739.a7bd48","type":"ftp","z":"","host":"localhost","port":"21","secureOptions":"","user":"admin","connTimeout":"","pasvTimeout":"","keepalive":""}]

```

![catch-ftp-specific-times](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b281f0f03f0f181164cbbe91795e5ef03388184.png)

In this case, what should I do?  
Any hint will be great.  
Thanks!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 February 2021 16:31 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/2 "2021-02-10T16:31:04Z")

</div>

somthing like this , untested as no ftp node on my machine.

```auto
[{"id":"faeb86e6.459f98","type":"change","z":"8d8a515a.78af18","name":"count ++ and ftp vals","rules":[{"t":"set","p":"count","pt":"msg","to":"error.source.count + 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":1500,"wires":[["46bbcb02.5fae34"]]},{"id":"46bbcb02.5fae34","type":"switch","z":"8d8a515a.78af18","name":"count greater than 6","property":"count","propertyType":"msg","rules":[{"t":"lt","v":"7","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":390,"y":1380,"wires":[["7197c896.b788c8"],["6d3c581.f0c04a8"]]},{"id":"b327d5f9.4a55f8","type":"catch","z":"8d8a515a.78af18","name":"catch [ftp] node","scope":["7197c896.b788c8"],"uncaught":false,"x":170,"y":1500,"wires":[["faeb86e6.459f98"]]},{"id":"6d3c581.f0c04a8","type":"change","z":"8d8a515a.78af18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Failed to send file!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":1420,"wires":[["13e0fbb5.197cc4"]]},{"id":"7197c896.b788c8","type":"http request","z":"8d8a515a.78af18","name":"ftp simulate","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://www.hfhfhhhdjk.com","tls":"","persist":false,"proxy":"","authType":"","x":760,"y":1360,"wires":[[]]},{"id":"958f10a1.7f7","type":"inject","z":"8d8a515a.78af18","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"count","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ftp values etc","payloadType":"str","x":160,"y":1380,"wires":[["46bbcb02.5fae34"]]},{"id":"13e0fbb5.197cc4","type":"debug","z":"8d8a515a.78af18","name":"Failed to send file!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":1420,"wires":[]}]

```

[edit] no need for context storage.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [11 February 2021 01:11 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/3 "2021-02-11T01:11:45Z")

</div>

@E1cid Thank you for your effort!  
Based on your code, I replaced _count greater than **6** _ with _count greater than **20** _,  
the error as described above still appears...

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [11 February 2021 01:28 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/4 "2021-02-11T01:28:59Z")

</div>

I wonder if it is possible to change the value of maximum number of catches !?  
I'm trying to search this way...

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 February 2021 08:07 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/5 "2021-02-11T08:07:59Z")

</div>

No just delete error property count, `msg.error.source.count` each loop

```auto
[{"id":"958f10a1.7f7","type":"inject","z":"8d8a515a.78af18","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"count","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ftp values etc","payloadType":"str","x":160,"y":1380,"wires":[["46bbcb02.5fae34"]]},{"id":"46bbcb02.5fae34","type":"switch","z":"8d8a515a.78af18","name":"count greater than 6","property":"count","propertyType":"msg","rules":[{"t":"lt","v":"20","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":390,"y":1380,"wires":[["7197c896.b788c8"],["6d3c581.f0c04a8"]]},{"id":"6d3c581.f0c04a8","type":"change","z":"8d8a515a.78af18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Failed to send file!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":1420,"wires":[["13e0fbb5.197cc4"]]},{"id":"d0c9a4de.c79f38","type":"delay","z":"8d8a515a.78af18","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":390,"y":1440,"wires":[["46bbcb02.5fae34"]]},{"id":"7197c896.b788c8","type":"http request","z":"8d8a515a.78af18","name":"ftp simulate","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://www.hfhfhhhdjk.com","tls":"","persist":false,"proxy":"","authType":"","x":760,"y":1360,"wires":[[]]},{"id":"13e0fbb5.197cc4","type":"debug","z":"8d8a515a.78af18","name":"Failed to send file!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":1420,"wires":[]},{"id":"faeb86e6.459f98","type":"change","z":"8d8a515a.78af18","name":"clear error","rules":[{"t":"set","p":"error.source.count","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"count","pt":"msg","to":"count+ 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1500,"wires":[["d0c9a4de.c79f38"]]},{"id":"b327d5f9.4a55f8","type":"catch","z":"8d8a515a.78af18","name":"catch [ftp] node","scope":["7197c896.b788c8"],"uncaught":false,"x":170,"y":1500,"wires":[["faeb86e6.459f98","ea5b1d29.6d31f"]]},{"id":"ea5b1d29.6d31f","type":"debug","z":"8d8a515a.78af18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":240,"y":1620,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [12 February 2021 06:44 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/6 "2021-02-12T06:44:35Z")

</div>

> [@minhhn0205](#):
>
> Message exceeded maximum number of catches

@E1cid Thank you very much!  
I also think like @E1cid and have done it.  
I deleted _msg.error_ right after the `catch` node.

![catch-ftp](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/17f897faf1de8cbb3f9c52a8c2e45f56dac5ab52.png)

---

<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:** [26 February 2021 06:45 UTC](https://discourse.nodered.org/t/how-to-catch-1-error-many-times/40753/7 "2021-02-26T06:45:30Z")

</div>

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