Examples
Error Recovery
Error Recovery Pattern
Learn how to handle errors gracefully with Boundary.
Boundary exposes typed error classes that allow you to implement sophisticated recovery logic.
Example Implementation
import { Boundary, RateLimitError, AuthError, NetworkError } from "boundary-sdk";
const boundary = new Boundary({
github: { auth: { token: process.env.GITHUB_TOKEN } }
});
async function fetchUserWithRetry(username: string, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const { data } = await boundary.github.get(`/users/${username}`);
return data;
} catch (error) {
if (error instanceof RateLimitError) {
// Boundary gives you the exact reset time
const waitTime = error.resetAt.getTime() - Date.now();
console.log(`Rate limited. Waiting ${waitTime}ms...`);
await new Promise(resolve => setTimeout(resolve, waitTime));
continue;
}
if (error instanceof AuthError) {
console.error("Authentication failed. Check your token.");
throw error;
}
if (error instanceof NetworkError && attempt < maxRetries - 1) {
console.log(`Network error. Retrying (${attempt + 1}/${maxRetries})...`);
await new Promise(resolve => setTimeout(resolve, 1000 * (attempt + 1)));
continue;
}
throw error;
}
}
}On this page
- Overview