How to stop workflow execution and still return an error response to webhook

Hi everyone,

I’m running into a problem with error handling in workflows that start with a Webhook node.

  • If I set nodes to Stop Workflow on Error, the workflow fails immediately and I cannot return any response to the webhook caller. The client just hangs without a response.

  • If I set nodes to Continue on Fail (using error output), then both the error path and the success path continue. This means even if the node fails and I send an error response, the workflow continues running down the success branch, which is not what I want.

  • I also tried using a dedicated Error Workflow, but since that doesn’t have access to the original webhook, I can’t send a response back to the client from there either.

What I want is:

  • If any node fails, I want to stop the entire workflow.

  • At the same time, I want to return an error message (JSON) to the webhook caller.

Right now the only option I see is to build lots of IF checks after each node to detect errors manually, but that feels messy and unscalable. Is there a clean way to do this in n8n?

Thanks in advance!

Hey @fatiimahoseini a simple solution is to use a “Response” Node + “Stop Workflow” node.

flowchart LR
    A[Webhook] --> B[Your Workflow Nodes]
    B -- Success --> C[Response Node\n200 OK]
    B -- Error --> D[Response Node\n4xx/5xx Error]
    D --> E[Stop Workflow Node]

Thanks for the suggestion :folded_hands:
If I understood you correctly, the Response + Stop Workflow pattern works well if the error happens at the very end of the flow.
But in my case, errors can happen in the middle of the workflow, right after the Webhook node.
Since I need to return a response immediately and also stop the whole execution, using “Continue on Fail” means the success branch still continues, and using “Stop on Error” prevents me from returning any response at all.

So I’m still stuck with this issue for mid-flow errors — either the workflow doesn’t stop, or the client never gets a response.

@fatiimahoseini Your analysis is 100% correct

Looking at your JSON, here’s a way to fix it

  1. Modify Your “Get User ID” Node
{
  "parameters": {
    "workflowId": {
      "__rl": true,
      "value": "ZmhqzUJQ8Xn1AtEY",
      "mode": "list",
      "cachedResultName": "User Authorization"
    },
    "workflowInputs": {
      "mappingMode": "defineBelow",
      "value": {
        "headers": "={{ $json.headers }}"
      }
    },
    "options": {
      "waitForSubWorkflow": true
    }
  },
  "type": "n8n-nodes-base.executeWorkflow",
  "typeVersion": 1.2,
  "position": [1024, 0],
  "id": "90c2a3b2-07cb-4a6f-a232-6f8178b2244a",
  "name": "Get User ID",
  "alwaysOutputData": true,
  "retryOnFail": false,
  "onError": "continueErrorOutput"  // ← Keep this!
}
  1. Create a new function node after error output
// Format consistent error response
const error = $input.first().json.error;

return [{
  json: {
    status: "error",
    message: error.message || "Processing failed",
    code: error.code || 500,
    timestamp: new Date().toISOString()
  }
}];
  1. Update your respond nodes
{
  "parameters": {
    "respondWith": "json",
    "responseBody": "={{ $json }}",
    "responseCode": "={{ $json.code }}",
    "options": {}
  },
  "type": "n8n-nodes-base.respondToWebhook",
  "typeVersion": 1.4,
  "position": [1024, 160],
  "id": "845b0bb7-c612-4d63-8f62-ea19f5b8208f",
  "name": "Respond Error"
}
  1. Add stop workflow after response
{
  "parameters": {
    "errorMessage": "Workflow stopped due to error"
  },
  "type": "n8n-nodes-base.stopAndError", 
  "typeVersion": 1,
  "position": [1024, 240],
  "id": "stop-after-response",
  "name": "Stop After Response"
}

Let me know what you think

Sorry for the late reply.
We had a project deadline and decided to postpone implementing the full error handling for later. For now, I just handled a few critical errors quickly with simple IF nodes and responses so the flow wouldn’t break. I haven’t tested your suggestion yet, but will definitely get back to it soon. If it solves the issue, I’ll mark it as the solution. Thanks a lot for your help!

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