I have a server action and I'm calling an API.With the response of that API,i have few more logics in the flow.If the API fails,now my flow ends throwing an error.But i need to complete the flow even if the api fails.What should id do?
Hi @Joe AJ
Hi Joe AJ,
As every one is suggesting you can use onAfterResponse event to customize the request . So you can tamper the Http Status code to 200 or 201.
Regards
Devendra
Hi capture the error, and then continue on:
https://success.outsystems.com/documentation/11/developing_an_application/implement_application_logic/handle_exceptions/
Hi Joe,
Please go through the below link for refrence:
https://success.outsystems.com/documentation/11/extensibility_and_integration/rest/consume_rest_apis/handling_rest_errors/
Regards,
Amreen
You are sharing documentation for O10 not O11.
I apologize , mistakenly clicked on O10.
Now edited the link
Please go through this link below for reference:
https://success.outsystems.com/documentation/11/extensibility_and_integration/rest/expose_rest_apis/customize_rest_api_responses/
Neha
Hi,You can add you custom logic in the "OnResponse" In the api Method.
Make note.
The attributes of the "Response" input parameter contain only the response body in serialized JSON format and in binary format . They don't include the headers that are part of the response.
Hello Joe,
In the exposed REST API, set the property On Response to New OnResponse.
You can add you custom logic in the "OnResponse" In the api Method.
https://success.outsystems.com/documentation/11/extensibility_and_integration/rest/expose_rest_apis/customize_rest_api_responses/?_gl=1*1xqciqq*_ga*MTYwOTQ3MTQyOC4xNzAwODA1NzM5*_ga_ZD4DTMHWR2*MTcwNDcxMzEyNC41LjEuMTcwNDcxMzUyNy42MC4wLjA.
I assume when you talk about the API "failing", an exception is generated (e.g. because the API sends a 404, or there is a time-out). In that case, as Appoorv explained, the trick is to wrap the API call in it's own action, and handle exceptions in that action. Create an Output parameter, like "IsSuccess", and only set it when the API finishes. In the calling action, you can then test the IsSuccess boolean, and handle it accordingly.
If the only problem is non-200-series HTTP status codes (like 404 in case of resource not found), you can do as Devendra suggested, add an OnAfterResponse and set the status code to a 200-series code, which will not trigger an exception. Additionally, you can add the original status code to the output (e.g. as a header parameter), so you know it's an error (if the API does not send a nice error message).