I've created an OnAfterResponse event handler when calling an API that's designed to enrich the ResponseText with StatusCode and StatusLine values.

The process involves Deserializing the response text as per:

Is it possible to set the Data Type at run time? The problem I am facing is that the implementation of the API's I'm consuming looks like this:

Each end point has it's own return data structure that needs to be deserialized, but each end point triggers the same OnAfterResponse event which can only handle the Data Type configured at design time.

Ultimately, I'm just looking to handle the HTTP response codes rather than have OutSystems simply throw an exception if the HTTP status is not 200. We need to be a little more granular in handling API exceptions.

Any help or suggestions would be welcomed.

Thanks,

Ben

Hi Ben,

That is not possible with the JSONDeserialize/Serialize actions.

But why do you need to deserialize/serialize the ResponseText if you only whant to custom handle the HTTP response code?

https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Expose_REST_APIs/Change_the_HTTP_Status_Code_of_a_REST_API

Regards,

Daniel

Hi Daniël,

Thanks for your response. I think the link you included in your answer is assuming that it is OutSystems that is exposing the API's, but they are in fact 3rd party so I don't think it's applicable to my case.

The reason I'm deserializing/reserializing is so I can embed the HTTP response codes in the structure returned by the API call. The default behavior is for OutSystems to throw an exception when the response is not 2xx. I need to be able to examine the response code from each end point. Something like:

Ultimately, if the module calling an API had access to the response status code and status line (eg: something like GetFunction1.StatusCode) that would be ideal.

Thanks again for taking the time to reply.

Ben

Solution

Hi,

My apology that my answer was not addressing your question correctly.

There is an old post describing two alternative solutions for your problem.

https://www.outsystems.com/forums/discussion/26455/get-the-http-status-code-returned-by-a-failed-consumed-rest-web-service/

Then there is an excellent article on the topic

https://www.linkedin.com/pulse/handling-http-status-codes-when-consuming-rest-rui-barbosa

Especially this article might help you.

Regards,

Daniel


Solution

Daniël - to use the Aussie vernacular, you are a dead set legend!

The link you provided to Rui's article was particularly helpful. I'm surprised all of my Googling did not turn it up.

Very much appreciated. Thank you.

Ben

Ben Wolrige wrote:

Daniël - to use the Aussie vernacular, you are a dead set legend!

The link you provided to Rui's article was particularly helpful. I'm surprised all of my Googling did not turn it up.

Very much appreciated. Thank you.

Ben

Haha, i don't know, that would be a lot of credit just for being able to google that.

Any how, glad I could help.