RetryableError
When a RetryableError is thrown in a step, it indicates that the workflow should retry a step. Additionally, it contains a parameter retryAfter indicating when the step should be retried after.
You should use this when you want to retry a step or retry after a certain duration.
import { RetryableError } from "workflow"
async function retryableWorkflow() {
"use workflow"
await retryStep();
}
async function retryStep() {
"use step"
throw new RetryableError("Retryable!")
}The difference between Error and RetryableError may not be entirely obvious, since when both are thrown, they both retry. The difference is that RetryableError has an additional configurable retryAfter parameter.
API Signature
Parameters
| Name | Type | Description |
|---|---|---|
options | RetryableErrorOptions | |
message | string |
RetryableErrorOptions
| Name | Type | Description |
|---|---|---|
retryAfter | number | StringValue | Date | The number of milliseconds to wait before retrying the step. Can also be a duration string (e.g., "5s", "2m") or a Date object. If not provided, the step will be retried after 1 second (1000 milliseconds). |
Examples
Retrying after a duration
RetryableError can be configured with a retryAfter parameter to specify when the step should be retried after.
import { RetryableError } from "workflow"
async function retryableWorkflow() {
"use workflow"
await retryStep();
}
async function retryStep() {
"use step"
throw new RetryableError("Retryable!", {
retryAfter: "5m" // - supports "5m", "30s", "1h", etc.
})
}You can also specify the retry delay in milliseconds:
import { RetryableError } from "workflow"
async function retryableWorkflow() {
"use workflow"
await retryStep();
}
async function retryStep() {
"use step"
throw new RetryableError("Retryable!", {
retryAfter: 5000 // - 5000 milliseconds = 5 seconds
})
}Or retry at a specific date and time:
import { RetryableError } from "workflow"
async function retryableWorkflow() {
"use workflow"
await retryStep();
}
async function retryStep() {
"use step"
throw new RetryableError("Retryable!", {
retryAfter: new Date(Date.now() + 60000) // - retry after 1 minute
})
}