How does Error Objects works?

Describe the problem/error/question


I don’t know how to make the node “Stop and Error” with the “Error Object” option work, the documentation says to set a JSON format, but the node doesn’t return anything, even if I catch it in a parent workflow.

What is the error message (if any)?

No error message, the output of the “Stop and Error” node is just empty, even if i catch it in a parent workflow

Please share your workflow

Share the output returned by the last node

Nothing as been outputed

Information on your n8n setup

  • n8n version: 1.89.2
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system:

First: Create Handle the error workflow

Here is a simple demo to catch the error

Second : Set up the Error workflow for this workflow

The error workflow will be triggered when this workflow throw an error

And only the execution is production. Manual trigger won’t execute the error workflow from my testing

Essentially it’s like purposefully throwing an error in Javascript where you would normally use the throw statement. Now in the case of n8n, you need something to catch the error as this basically crashes the workflow on purpose with a custom error. To make this work, look at the example below. PS this only really works when the workflow triggers in production and NOT while clicking the test workflow button.

We need to set the properties of the workflow to tell it which workflow is responsible for catching the error. In this case I set it to the same workflow simulating a try/catch. This could be any other workflow, for exampe in my production setups, I have a single “error workflow” I use to ctach all errors from all workflows and then email myself the errors with execution data referenced.

Once you enable this workflow and the scheduler trigger, you’ll see one execution with error and another where the Error trigger picked up the error details:

1 Like

Thank you everyone!

In our case, we have the following setup:

  • A parent workflow triggered by a Webhook, which calls a subworkflow and then returns a response using a “Respond to Webhook” node.
  • A subworkflow that may throw different errors using “Stop and Error” nodes.

The issue is: if we rely on a global Error Workflow set in the workflow settings, we won’t be able to catch those errors within the main execution flow. As a result, we can’t properly return a response via the “Respond to Webhook” node in the parent workflow.

So we’re looking for a way to handle subworkflow errors gracefully inside the parent workflow, without relying on the global error workflow.

You should NOT call sub workflows using webhooks. Rather use the Execute Workflow node for this. This way if any node in your sub flow errors out, then the parent / calling workflow will catch it.

Here’s an example of one of our production flows. The sub flow had an error in one of the code nodes, but the parent caught it

And here is the result from the error workflow which then emailed us:

1 Like

@Wouter_Nigrini Thank you for your answer!

I didn’t explain myself clearly in my previous message, but we actually do have the same setup as the example you shared. Here’s a screenshot of our workflow with the Webhook trigger:

What I’m trying to achieve is the ability to catch the error object inside the If node, so I can pass it to the “Error Response” node and return it as the Webhook response.

If I use a global Error Workflow, I won’t be able to send the error back as part of the response to the original Webhook call.

Oh the easiest way to do this, and similarly on any node, is to set the on error setting to continue using output:

This will create a new leg for which you dont need an IF node anymore

Here is an example:

This workflow calls itself while forcing the error. I can only get this to work by setting the throw to a message and not an object.

Yes, that’s the point i tried to describe originally, I can’t get this to work by setting the throw to an “Error Object” :pensive:

It only works when I set it to an “Error Message”

Why do you need to set an object anyway in the error response? You want to bubble your errors up to the main calling parent workflow and then from there decide how to handle the errors via REST responses. So if setting an error code was the only reason, then just do it in the parent:

I want the subworkflows to be able to throw both the HTTP status code and the error message. These values depend on the specific context of the error, which is why I would prefer the subworkflows to handle and return them directly.

If I have to manage everything in the parent workflow, I would need to build a full system of conditions to interpret and handle each possible error from each subworkflow, which adds a lot of complexity and duplication.

The “Error Object” option in the “Stop and Error” node seems like the perfect solution for this use case — but unfortunately, it doesn’t seem to work as expected (or I can’t find the right solution to use them).

1 Like

Then simply JSON.stringify your error object and parse it in the main service like this

It seems like the “catching” of the error will always return a string value even if an object was thrown.

2 Likes

Yes i think i will do this, thank you for your answers !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.