Catch Error from final node in webhook response

My webhook is connected to an HTTP module that makes a request to an API.

There are times when the API returns an error because it has no data.

Error: StatusCodeError: 404 - {"header":{"statut":404,"message":"No elements found with those query parameters"}}
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest.node.js:762:27)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:369:47

Is there a way to catch that Error back in the webhook ?

I tried with all different response modes (“last node” or “on received”) and with all response data (all entries, first entry json, first entry binary) => But the response I get is always my initial request.

Any idea how to solve that ? Is that doable ?

Hi @alexsonnay! You are right, you’d need to select ‘Last Node’ from the Response Mode dropdown list in the Webhook node. Next, in the HTTP Request Node, you’d have to add the Ignore Response Code and the Full Response field using the Add Options button and toggle them to active (green). You’d also need to select ‘File’ from the Response Format dropdown list. I’ve attached a workflow below which illustrates this.

{
  "nodes": [
    {
      "parameters": {
        "url": "https://docs.n8n.io/sdfasff",
        "responseFormat": "file",
        "options": {
          "fullResponse": true,
          "ignoreResponseCode": true
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        740,
        300
      ]
    },
    {
      "parameters": {
        "path": "3b013a34-6b7a-48bf-bbef-82abac7c328d",
        "responseMode": "lastNode",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        500,
        300
      ],
      "webhookId": "3b013a34-6b7a-48bf-bbef-82abac7c328d"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

In case you don’t want to set the Ignore Response Code to true, you might want to take a look at the Error Trigger node.

Hope that helps, have fun! :slight_smile:

Thanks :rocket::rocket::rocket::rocket::rocket::rocket::rocket::rocket:

1 Like