Hi all
New guy here…
We’ll be using n8n as an integration platform across multiple systems. Typically, the flows would follow the general pattern
- Triggered from a webhook
- Incoming info is validated
- A series of nodes that do work in one or more systems via HTTP Requests or similar.
- provide http response code and return payload to caller
Any one of the actions from validation onwards could ‘fail’, meaning the flow needs to terminate, and a suitable response sent to the caller.
I’m trying to work out the best way of handling this, but struggling to come up with an good option.
My first thought – which was to tell the webhook to return the ‘last executed’ node output, and use an expression to define the webhook return HTTP code, doesn’t fly – as described at How do I change or status code of a webhook - #4 by RicardoE105 we can’t currently do this.
My next thought was to use the Respond to Webhook node, and add an error trigger to the flow. When fired, the error trigger can then be used as the entry point for defining an error return. However:
- Although the Error trigger is triggered if a node within the flow throws an error (e.g. if I have a function item that throws an error or an http call returns a 400), and the execution record indicates that the webhook response was executed, , the actual return to the caller is code 200 with {“message”:“Workflow did error.”}
For example
At present, it seems the only way I can reliably manage the error handling is to
- On each HTTP request, set Ignore Return Code Retrieve full return
- Put an if…then or switch after each call
This is obvious achievable, but with more complex flows where we have a longer sequence of nodes
- Complicates the flow
- Makes it harder to use sub-flows to capture common mini-sequences
I’m sure that this is mainly lack of knowledge/experience on my part, and I’m missing some key piece, but if you have any advice, I’d be grateful.
Example flows.
There are two flows here
- Sub-Flow - simply mimicks a 3rd party system – returning a success or failure code depending on the input.
- Main Flow uses a GET webhook, and calls the sub-flow. It expects a parameter “code” as an integer e.g from curl
successful call- curl http://localhost:5678/webhook/tester1?code=200
Error processing call 1 - curl http://localhost:5678/webhook/tester1?code=400
Error processing call 2 – curl http://localhost:5678/webhook/tester1
Sub-Flow
Main Flow