Build anything with
Build reliable, long-running processes with automatic retries, state persistence, and observability built in.
import { RetryableError, FatalError } from "workflow";async function callAPI(endpoint) { "use step"; const response = await fetch(endpoint); if (response.status >= 500) { // Uncaught exceptions are retried by default throw new Error("Server error"); } if (response.status === 404) { // Explicitly throw a FatalError to skip retrying throw new FatalError("Resource not found. Skipping retries."); } if (response.status === 429) { const retryAfter = response.headers.get('Retry-After'); // Customize the duration before retrying throw new RetryableError("Too many requests. Retrying...", { retryAfter: parseInt(retryAfter) }); } return response.json();}// Customize max retrieschargeCard.maxRetries = 5;