Software Development

How to Handle an External API Call Error in Workflows

The Okta Workflows team holds weekly community office hours where you can ask questions about workflows, uses cases, and share what you are working on.

I’m publishing some of questions and answers from the office hours as I believe they are extremely valuable how-to’s.

On to the question.

How to handle an external API call error in Workflows?

When calling an external API results in an error you want to gracefully handle the error and continue the flow execution. One way to handle an error is to use Error Handling – If Error card. It’s similar to try/catch logic.

The card has two sections Try and If Error.

In the Try section you place the API Connector card followed by any other logic. In this example there is a single Assign card to create a success message. You can add other cards as well. The message is then mapped to If Error card’s output.

If Error card – success section

In the If/Else section there is a default error message followed by any other logic. In this example it’s again a single Assign card which olds the error message. The message is then mapped to If Error card’s output.

If Error card – error section

Tip: Learn how to create outputs for an If/Else card.

After the If Error card you can add additional logic. Here is an example of sending a success or an error message to a Compose card.

Now you can test the flow. The flow uses a service called mock.codes. mock.codes provides for an easy way to reference and test HTTP responses.

Running the flow with HTTP response 200 (https://mock.codes/200) that results in success:

Running the flow with HTTP response 500 (https://mock.codes/500) that results in Internal Server Error:

The flow chart can help visualize the flow logic at a high-level:


Have a question about Okta Workflows? Not sure how to build a flow? Join the weekly community office hours to get help.

Published on Java Code Geeks with permission by Max Katz , partner at our JCG program. See the original article here: How to Handle an External API Call Error in Workflows

Opinions expressed by Java Code Geeks contributors are their own.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button