Handle errors on current workflows with custom nodes

Describe the problem/error/question

Hi. I’m setting up a basic workflow that includes a Webhook trigger (POST endpoint), then extracting the body of the request for a subsequent community node to perform data validation with a JSON Schema. If the data validation node returns a validation error, the webhook should respond with a 400. Otherwise, it should respond with a 201 with a Respond to Webhook node.

While the data validation node performs the validation correctly, I’m struggling to act upon that error. I’ve set the On Error -> Continue option, but the downstream node seems not to pick the error properly (Haven’t managed to identify the error even trying with a Edit Fields node to do a mapping). I’ve also set the On Error -> Continue (using error output) but the error branch never gets to execute even if the node throws an error.

At this point I’m not exactly sure if the custom node is not throwing the error properly (according to the base code, it’s throwing a NodeApiError with the validation errors) or it’s just me and my lack of knowledge of error handling in n8n. If it’s an issue with the custom node, I’d like to hear from you how to throw errors properly for this use case, so I can submit a PR. Otherwise, I’d appreciate a little help with the branching logic.

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: latest according to Docker Registry
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: MacOS 12.3.1

I’ve refactored the code following the recommended Mattermost node, and got the expected result. Will try to do a PR to the author

2 Likes

Sweet, thanks so much for your help with this @david001 and welcome to the community!