How to "catch" node.warn(msg)

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?

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 ?

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:

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);

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.

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

Genious :slight_smile: I like it.

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