# How to "catch" node.warn(msg)

**URL:** https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738
**Category:** General
**Created:** [6 October 2018 14:01 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738 "2018-10-06T14:01:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![EZS-JD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ezs-jd/32/2842_2.png) [@EZS-JD](https://discourse.nodered.org/u/EZS-JD)
#### Post date: [6 October 2018 14:01 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/1 "2018-10-06T14:01:30Z")

</div>

I love using the "catch" node to catch all errors from a flow and then pipe them to any notification system like Telegram, Email, etc.

Is there anything similar that works with node.warn()? How could I catch .warn() messages and send them on to some notification system?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [6 October 2018 14:08 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/2 "2018-10-06T14:08:49Z")

</div>

No ,sorry, warn messages only go to the sidebar and main console log.

I suppose in theory you could write your own log handler function and re-inject that via tcp or some such workaround.

Are there any in particular that you think worthy of being errors ?

---

<div class="post-metadata">

### Author: ![EZS-JD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ezs-jd/32/2842_2.png) [@EZS-JD](https://discourse.nodered.org/u/EZS-JD)
#### Post date: [6 October 2018 15:42 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/3 "2018-10-06T15:42:24Z")

</div>

Not sure what you mean with your last question? But thanks for your answer.

I can obviously use separate node-outputs for such notifications, but that's more work and more clutter. I like the functionality of the catch node... like magic 🙂

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [6 October 2018 16:17 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/4 "2018-10-06T16:17:12Z")

</div>

Did you try node.error ?

Source: [https://nodered.org/docs/writing-functions](https://nodered.org/docs/writing-functions)

#### Handling errors

If the function encounters an error that should halt the current flow, it should return nothing. To trigger a Catch node on the same tab, the function should call `node.error` with the original message as a second argument:

```auto
node.error("hit an error", msg);

```

---

<div class="post-metadata">

### Author: ![EZS-JD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ezs-jd/32/2842_2.png) [@EZS-JD](https://discourse.nodered.org/u/EZS-JD)
#### Post date: [9 October 2018 14:54 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/5 "2018-10-09T14:54:00Z")

</div>

Andrei: Yes that's what I'm using currently. I'd like to have similar capability for "non-errors" that could use a different notification pathway.

---

<div class="post-metadata">

### Author: ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)
#### Post date: [9 October 2018 17:28 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/6 "2018-10-09T17:28:48Z")

</div>

Hi @EZS-JD ,

You could always prefix your error messages with the severity

```auto
node.error("[error] hit an error", msg);
node.error("[warning] hit a warning", msg);

```

and then filter with a switch after your catch node.

---

<div class="post-metadata">

### Author: ![EZS-JD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ezs-jd/32/2842_2.png) [@EZS-JD](https://discourse.nodered.org/u/EZS-JD)
#### Post date: [10 October 2018 13:53 UTC](https://discourse.nodered.org/t/how-to-catch-node-warn-msg/3738/7 "2018-10-10T13:53:13Z")

</div>

Genious 🙂 I like it.

Haven't worked with the switch node yet, this is the perfect use-case. Thanks!
