Node-Red - How to catch errors from Write File Node?

141 Views Asked by At

I've a Write File node in the flow as bellow:

enter image description here

Write File node is set to append a line to a file, when I set a wrong address for the file path, it's not throwing any error, it's options are as this:

enter image description here

File is not exists and it's not creating the file which is correct, but how can I get the error and change the response based on it?

1

There are 1 best solutions below

0
hardillb On

If the LOG_FILE_PATH env var is empty then the file-write node will only print a warning message to the debug sidebar and no error will be thrown for the catch node to receive.

If the path points to a location or file that the user running Node-RED can not access, then it will throw an exception on the first message only, it will not continue to throw errors for every input message, so it will not be possible to send a 500 error for every request.

It also appears that file-write node outputs even if it throws an error so the http-response node will already have responded by the time the output of the catch node reaches it.

You may want to raise this on the Node-RED Discourse forum to discuss a feature request to change this behaviour as it's probably sub-optimal