84
Views
10
Comments
Solved
Handle API Response

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?

2022-09-12 05-19-11
Apoorv Choubey
Solution

Hi @Joe AJ 

  • First of all create a server action and write logic inside that server action where probability of error high and handle that error inside that server.
  • Now you will throw out of that server action.
  • Now call that server action which is create in first step.
  • after calling that server action write the remaining logic that you want to run.
2020-09-18 09-37-36
Devendra Baghel
Solution

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 



2025-01-09 14-56-57
IQ78

Hi capture the error, and then continue on:

https://success.outsystems.com/documentation/11/developing_an_application/implement_application_logic/handle_exceptions/

2021-10-17 12-36-16
Amreen Shaikh

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

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

You are sharing documentation for O10 not O11.

2021-10-17 12-36-16
Amreen Shaikh

I apologize , mistakenly clicked on O10.

Now edited the link

2022-09-12 05-19-11
Apoorv Choubey
Solution

Hi @Joe AJ 

  • First of all create a server action and write logic inside that server action where probability of error high and handle that error inside that server.
  • Now you will throw out of that server action.
  • Now call that server action which is create in first step.
  • after calling that server action write the remaining logic that you want to run.
2022-01-13 11-06-04
Neha Sheikh
Champion
2023-08-28 12-30-49
Bhushan Futane

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. 

2024-07-09 06-45-01
Adarsh
2020-09-18 09-37-36
Devendra Baghel
Solution

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 



2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Joe,

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).


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.