A state can run into errors for various reasons. In Zoho Circuit, most of the state definition errors are intimated before saving the circuit. Only functional states, such as function, webhook, and circuit, are bound to have runtime errors, the error handling feature is only supported for functional states. Runtime errors are classified into the following four scenarios:
- On Timeout
- On Authorization Failure
- On Execution Failure
- Custom Error
All four error handling options have two common fields, Retry and Fallback. You can define the error handling fields for a state under Configuration.
On Timeout
When a functional state runs longer than the expected time, timeout errors occur. For handling timeout errors in
code view, the field value
"errorType": "Error.TimeOut" will be added.
On Authorization Failure
If a state fails because of insufficient privileges to access the specified code, the error is handled as an authorization failure. In code view, name value "errorType": "Error.AuthorizationFailure" is added.
On Execution Failure
When a state's execution fails due to some exception which cannot be processed, it can be handled using execution failure. In code view, name value "errorType": "Error.ExecutionFailure" is appended.
Custom Error
You can customize your error handling using the error code or error message provided by the state output. For this, you need to configure Exception Type and Exception Value.
- Exception Type - Provide 'Error Code' or 'Error Message' from the drop down using which the error handling must take place.
- Exception Value - Enter the exact value of error code or error message that will be received in the state output.
By default, Custom Error name is set to Error 1, Error 2 or Error 3 based on the number of custom errors configured. To change the default name, click the 'edit' icon and specify a name.
For custom errors in code view, name value "errorType": "Error.Custom" is appended.
All the above error handling options configures two fields: Retry and Fallback.
Retry
You can retry the failed state for a specific number of attempts within predefined intervals using this option.
Retry consists of three fields:
- Delay - Set the time, number of seconds after which the state must be retried after failure.
- Attempt - Set the number of times the state has to be retried
- Step Delay - Increase the delay time for each attempt by multiplying the Delay time with the Step Delay number set.
New Delay Time = Delay * Step Delay
For example, suppose the Delay is set to 5 seconds, Attempt is set to 3 and Step Delay is set to 2 for a 'Retry'. Then the first retry attempt takes place after 10 (5*2) seconds, the second attempt takes 20 (10*2) seconds and the third attempt takes 40 (20*2) seconds to get executed.
New Delay Time = Delay * Step Delay
1st attempt > 10s = 5s * 2
2nd attempt > 20s = 10s * 2
3rd attempt > 40s = 20s * 2
Fallback
In case of failure or error, the failed state can fall back to another state to continue the execution.
For setting up fallback, configure the following two fields:
- Next - Set the state name to which the inputs of the failed state and error output have to be passed'.
- Result - Set the field name in which the error received for the failed state has to be sent to the fallback state.
A sample state that handles an 'On Timeout' and 'Custom Error' in
code view is displayed below.
- "SayHello": {
- "type": "function",
- "next": "branch",
- "parameter": {
- "name": "James"
- },
- "functionName": "HelloWorld_name",
- "onError": [
- {
- "errorType": "Error.TimeOut",
- "retry": {
- "delay": 3,
- "attempt": 2,
- "stepDelay": 1
- },
- "fallback": {
- "result": "$.erroroutput",
- "next": "HelloWorld"
- }
- },
- {
- "errorType": "Error.Custom",
- "errorName": "Error 1",
- "errorCode": "101",
- "retry": {
- "delay": 3,
- "attempt": 3,
- "stepDelay": 1
- },
- "fallback": {
- "result": "$.error",
- "next": "Hello"
- }
- }
- ]