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

CodeMeaningAction
not_connectedUser has not connected this providerRedirect to getConnectUrl()
token_expiredOAuth token has expiredPrompt user to re-authorize
invalid_api_keyAPI key is missing or invalidCheck your API key configuration
rate_limitedToo many requests to the providerBack off and retry after a delay
provider_errorUpstream provider returned an errorCheck 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 yet
const url = integrations.getConnectUrl('gmail')
// Redirect them to authorize
break
case 'token_expired':
// OAuth token expired, prompt re-auth
const reAuthUrl = integrations.getConnectUrl('gmail',
'https://my-app.un.leash.build/settings'
)
break
case 'rate_limited':
// Back off and retry
await new Promise(r => setTimeout(r, 5000))
break
default:
console.error(`Integration error: ${err.message}`)
}
}
}

TypeScript: Errors are instances of IntegrationError with a code string and message string.