SDK
Error Handling
All SDK methods throw typed errors when the platform returns a non-success response. Errors include a machine-readable code field for programmatic handling.
Error Codes
| Code | Meaning | Action |
|---|---|---|
| not_connected | User has not connected this provider | Redirect to getConnectUrl() |
| token_expired | OAuth token has expired | Prompt user to re-authorize |
| invalid_api_key | API key is missing or invalid | Check your API key configuration |
| rate_limited | Too many requests to the provider | Back off and retry after a delay |
| provider_error | Upstream provider returned an error | Check the error message for details |
Handling Errors
Each language has its own error type and pattern. See the examples below for idiomatic error handling in each SDK.
error-handling.ts
import { IntegrationError } from '@leash/sdk/integrations'try {const messages = await integrations.gmail.listMessages()} catch (err) {if (err instanceof IntegrationError) {switch (err.code) {case 'not_connected':// User hasn't connected Gmail yetconst url = integrations.getConnectUrl('gmail')// Redirect them to authorizebreakcase 'token_expired':// OAuth token expired, prompt re-authconst reAuthUrl = integrations.getConnectUrl('gmail','https://my-app.un.leash.build/settings')breakcase 'rate_limited':// Back off and retryawait new Promise(r => setTimeout(r, 5000))breakdefault:console.error(`Integration error: ${err.message}`)}}}
TypeScript: Errors are instances of IntegrationError with a code string and message string.