RetryableError

Throw to retry a step, optionally after a specified duration.

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

Constructor

new RetryableError(message: string, options?: RetryableErrorOptions)
ParameterTypeDescription
messagestringThe error message
optionsRetryableErrorOptionsOptional configuration for retries

Instance Properties

PropertyTypeDescription
retryAfterDateThe date/time when the step should be retried. Defaults to 1 second from now when options.retryAfter is omitted.

RetryableErrorOptions

PropertyTypeDescription
retryAfter?number | StringValue | DateDelay before retrying. A number is milliseconds, a StringValue is a duration string (e.g. "5s", "2m"), or a Date for an absolute time. Defaults to 1 second (1000 ms) when omitted.

Static Methods

RetryableError.is(value)

RetryableError.is(value: unknown): value is RetryableError

Returns true if value is a RetryableError instance. Useful for checking caught errors without instanceof.

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