Forum Discussion
This is maybe a little bit difficult, but you can put the following filter after your parser
The expression is: $.entries().filter(v => v[1] != "").length > 0
which will find any instance where all of the values for the given input document are all empty and filter them out.
hey omair,
Have you tried the Exit snap? It allows you to set an error message that can be returned to the user.
If you call that via a triggered task, then you’ll get this kind of response.
[ { "failure" : "Pipeline execution failed while waiting for output", "reason" : "Snap errors: {ruuid=52e99318640a9a03d8681d0d_9b3dd03a-dde2-43e8-a0ba-fd58239c2a5d, reason=Number of input documents received is more than 0, label=Exit, resolution=Try passing less than or equal to 0 input documents, failure=Beep Boop! Failure!}", "resolution" : "Fix the reported errors" } ]
You’d still have to extract it from the reason String, so not the most user friendly way.
You could also do something like this:
Where the mapper returns the output before the exit snap is invoked using a sleep in a Script snap. This will return a response like
[ { "error": "Beep Boop! Failure!" } ]
Which is easier to deal with.
This isn’t the most elegant approach since there is a race condition between when the mapper’s output is written out and when the exit snap processes the document from its input stream.
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
GyanendraCould 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)
- bojanvelevski5 years agoValued Contributor
Are you referring to a custom binary header, so you could manipulate the response? If that’s the case, you can use Mapper to map the status and the message, than add a JSON Formatter snap, and add the incoming status and message in a binary header properties.
Understanding Synchronous and Asynchronous Execution of Triggered Tasks
Hope this helps,
Regards,
Bojan Velevski
Related Content
- 3 months ago