# Error catching and a function node to indicate errors

**URL:** <https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878>\
**Category:** General\
**Created:** [28 July 2018 01:33 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878 "2018-07-28T01:33:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2018 01:33 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/1 "2018-07-28T01:33:52Z")

</div>

Yes, I know I have been down here before.

I have since discovered the function of the "CATCH ALL" node.

So, to try and help myself on what is going on, I thought I would add a bit of extra stuff on that part of the flow.

```auto
[{"id":"e35ce20a.0fecd8","type":"catch","z":"b04360a6.da324","name":"","scope":null,"x":110,"y":1190,"wires":[["c31406ad.87dfa8","e237ff3a.70315"]]},{"id":"e237ff3a.70315","type":"function","z":"b04360a6.da324","name":"Name flow","func":"msg.topic = \"Logging flow\";\nnode.status({fill:\"red\",shape:\"dot\",text:\"ERROR\"});\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":1190,"wires":[["6bce9b2f.0d9fb4"]]}]

```

The FUNCTION node also sets a RED marker if that node sees an error.

I'm guessing a FULL DEPLOY would reset it?  
(No it doesn't)  
The node is set to a red indicator. I've looked at the error. How do I remove the indicator?  
If not that easy I may just not put the line in the node.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [28 July 2018 06:19 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/2 "2018-07-28T06:19:43Z")

</div>

you’ve done if and else statements before.

If you see an error draw a red dot  
else draw a green square

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 July 2018 08:07 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/3 "2018-07-28T08:07:17Z")

</div>

Here is an [example](https://flows.nodered.org/flow/2ec32b279faddcb3c4754df7bd10a4d1) showing a way to set/clear the status,

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 July 2018 10:19 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/4 "2018-07-28T10:19:46Z")

</div>

> [@Trying\_to\_learn](#):
>
> I'm guessing a FULL DEPLOY would reset it?  
> (No it doesn't)

I believe that a full deploy should reset it. Put a debug node on the output of the Catch and see if you are getting an error immediately on deploy.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2018 23:38 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/5 "2018-07-28T23:38:34Z")

</div>

UKMoose,

Yes, I have done (and had fun with) IF ELSE statements.

But the part that has/had me stuck was that as far as I can see, the output is only there if an error has happened.

So if there isn't an error, there is no output. Anyway, I'll look at the example from zenofmud.

Zenofmud,

Thanks.

I hadn't got that far with the catchall node.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2018 23:47 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/6 "2018-07-28T23:47:24Z")

</div>

Colin,

I may have been wrong in a FULL deploy doesn't clear it.

I mostly do modified nodes only. Sometimes a FULL.

I may have got the settings wrong when I posted it.

Oops.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [29 July 2018 09:18 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/7 "2018-07-29T09:18:04Z")

</div>

Take a look at the trigger node, that can send a second message after the first message comes in.  
So for example if theres an error, 20 seconds after the error a second message is sent with a different msg that then allows you to do your IF ELSE statement to reset the marker

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [30 July 2018 22:17 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/9 "2018-07-30T22:17:57Z")

</div>

Thanks.

I installed the "DSM" node and ran the flow.

When I press the error injection node, I get an error (not as per the expected error)  
"Unexpected token b in JSON at position 8"

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [31 July 2018 04:00 UTC](https://discourse.nodered.org/t/error-catching-and-a-function-node-to-indicate-errors/1878/11 "2018-07-31T04:00:43Z")

</div>

Ok, let me explain.

I loaded your flow.

I press the "ERROR" injection and I expect an error.

But not an ERROR.

What do I mean?

Well, I am expecting a "legitimate" error to be made.

But rather under the DSM I get an error saying that message about the unexpected token b in JSON at position 8.

Looking at the error node and the ok node, I am suspicious that the error would be more to do with foo and bar.

Not "unexpected token......"

As I don't talk the talk, I am unsure if that is an honest mistake when you wrote the code or what.

So I am no further down the understanding path than I was.

Sorry.

I'll read your reply again.  
Just in the mean time I seem to have killed my remote (main) NR machine and am suffering severe sinus problems.
