Forum Discussion
Hi Tlikarish,
I would like to make the pipe line status as failed instead of completed.
My rest API sends the status as ok where few record inserted and few failed. I am counting if failed records >0 , then I am logging those record in log then exiting with exit snap. But the pipeline status is not failing. It shows completed. I want the pipe line status should show as failed.
Regards
Gyanendra
Could you include some more information regarding your implementation and what you’re trying to do? If I understand your question you are trying to check if there were failed insertions. If so, then the task should respond with an error message and a non-200 status code. If that’s correct then you might look at this kind of pipeline.
You can use the JSON Generator to set the failed count, which will determine if there is an error. Here are some additional notes for the 4 key snaps required to get this done.
- This Router will check for failures and if surpasses the error threshold, routes the document to the bottom output view.
- The
Set Error
mapper snap will set an error message and status code that the task should return in the HTTP response. - The exit snap will surpass the threshold and is used to put the pipeline in a failed state.
- The JSON formatter can be used to set the status code on the HTTP response. This is done by setting a special field called
status
in the binary document header.
When executed as a triggered task, then you should see this kind of response. I removed some headers from the response to make it easier to read.
< HTTP/1.1 500 INTERNAL SERVER ERROR
< Date: Wed, 02 Nov 2022 20:33:46 GMT
< Content-Type: application/json; charset=utf-8
< X-SL-StatusCode: 500
< X-Snapi-pipeline-ruuid: XXXX08ba
...
<
[{"status":500,"error":"oh no!"}]
In the dashboard it’ll show up like this.
Here is an attached pipeline if you’d like to try it out.
exit-example_2022_11_02.slp (9.9 KB)