How to "catch" node.warn(msg)

#1

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?

0 Likes

#2

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 ?

0 Likes

#3

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 :slight_smile:

0 Likes

#4

Did you try node.error ?

Source: 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:

node.error("hit an error", msg);
0 Likes

#5

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.

0 Likes

#6

Hi @EZS-JD ,

You could always prefix your error messages with the severity

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

and then filter with a switch after your catch node.

1 Like

#7

Genious :slight_smile: I like it.

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

0 Likes