Retrying API with HTTP status code 202
Last updated
Was this helpful?
Last updated
Was this helpful?
There may be a case when you want the app to keep sending the same request until the result is ready. For example, you may want the API to keep returning 202 status code until the data is ready, and then return a 200 with all the data.
Below is the approach we suggest to implement this kind of logic:
Create a new action of the HTTP Request type (called here apiCall):
Specify the method and URL.
Select the Transform result toggle and in the Modify the result field add return {{res}};
.
This will return the status of the API request as, by default, the HTTP step returns the body of the response.
Create another action of the JavaScript Code type (called here callApiWithRetries) and specify the following code:
Here, the action is called programmatically with actions.apiCall.trigger()
, which allows you to easier control retry logic.
But you can also make this retry action generic and execute it providing actionName via params. To do so, you simply need to change the code to actions[params.actionName].trigger()
: