Ask Your Question
2

How to handle HTTP request with different status (200/400) ?

asked 2019-01-31 10:44:31 -0600

T1l3 gravatar image

updated 2019-02-04 04:31:55 -0600

I have a pipeline reading a csv file and doing POST request to an API for each lines.

POST request are done via a HTTP Client processor but I can receive a 200 response for a sucessful item created or a 400 with error fields. I want to send these errors to RabbitMQ but I don't know how to handle the 400 response, the pipeline stops and throw an error.

How to catch those 400 responses?

Edit: I followed @metadaddy 's answer to send error to another pipeline. Unfortunately I still don't retrieve the response. Here is some screenshots for easier readability.

original pipeline error output: image description

original pipeline > HTTP Client: image description

original pipeline > HTTP Client running getting error 400 from the API (normal behaviour needs to be catched):

image description

error pipeline > send output to RabbitMQ or raw file:

image description

content of the error file:

{ "Field2":"xxx", "Field2":"xxx, [...] }

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-01-31 16:42:16 -0600

metadaddy gravatar image

You can set On Record Error on the HTTP Client Processor to Send to Error, then configure error handling for the pipeline to send error records to a second pipeline, from which you can send them to RabbitMQ.

Alternatively, you could use one of the script evaluators to send the POST request, and handle the response in the script.

edit flag offensive delete link more

Comments

Thanks for you answer. I have done the first solution it works well but I get only the payload with data sent. Not the received response. Is it possible to get it too?

T1l3 gravatar imageT1l3 ( 2019-02-01 03:49:30 -0600 )edit

Looking at the code, the response body should be in the error. Dump the entire record to disk as JSON and you should be able to see it.

metadaddy gravatar imagemetadaddy ( 2019-02-01 09:34:32 -0600 )edit

I get the same record, a list of objects `{fields1: value, field2: value}` but still not the response. Did I miss some option ?

T1l3 gravatar imageT1l3 ( 2019-02-01 10:04:03 -0600 )edit

Hi, I edited my question with screenshots of the pipeline for easier readability.

T1l3 gravatar imageT1l3 ( 2019-02-04 04:36:13 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-31 10:29:23 -0600

Seen: 93 times

Last updated: Feb 04