Gmail Error Handlers
Built-in and custom error handling for Gmail
The Gmail plugin includes comprehensive error handling with built-in handlers for common error scenarios. You can also add custom error handlers to handle specific cases in your application.
New to Corsair? Learn about core concepts like error handling and retry strategies before customizing error handlers.
Full Implementation: For the complete, up-to-date error handler implementations, see the Gmail plugin source code on GitHub.
Built-in Error Handlers
The Gmail plugin automatically handles common error scenarios with sensible retry strategies.
Rate Limit Errors
Triggers: HTTP 429 status, or error messages containing "rate limit", "rate_limit", or "429"
Behavior:
- Maximum retries: 5
- Respects rate limit headers from Gmail
- Uses exponential backoff between retries
Authentication Errors
Triggers: Error messages containing:
Invalid CredentialsInvalid tokenToken expiredUnauthorized
Behavior:
- Maximum retries: 0 (no retries)
- Logs error to console
- Fails immediately for manual intervention
How to Fix:
- Verify your OAuth credentials are valid
- Check if the access token has expired
- Ensure the refresh token is valid
Permission Errors
Triggers: HTTP 403 status, or error messages containing:
ForbiddenInsufficient permissionsAccess denied
Behavior:
- Maximum retries: 0 (no retries)
- Logs warning to console
- Fails immediately for manual intervention
How to Fix:
- Check your OAuth scopes
- Ensure the required Gmail API scopes are granted
- Re-authorize the application
Resource Not Found Errors
Triggers: HTTP 404 status, or error messages containing:
Not FoundMessage not foundThread not found
Behavior:
- Maximum retries: 0 (no retries)
- Logs warning to console
- Fails immediately
Network Errors
Triggers: Error messages containing:
networkconnectioneconnrefusedenotfoundetimedout
Behavior:
- Maximum retries: 3
- Uses exponential backoff
- Logs warning to console
Default Error Handler
Triggers: Any error not matched by other handlers
Behavior:
- Maximum retries: 0 (no retries)
- Logs error to console
- Fails immediately
Custom Error Handlers
You can add custom error handlers to handle specific scenarios in your application.
Basic Custom Handler
gmail({
errorHandlers: {
CUSTOM_ERROR: {
match: (error, context) => {
return error.message.includes("custom_error_code");
},
handler: async (error, context) => {
console.log(`Custom error in ${context.operation}`);
return {
maxRetries: 2,
};
},
},
},
})Error Handler with Retry-After
gmail({
errorHandlers: {
QUOTA_EXCEEDED: {
match: (error) => error.message.includes("quota exceeded"),
handler: async (error, context) => {
return {
maxRetries: 3,
headersRetryAfterMs: 60000,
};
},
},
},
})For comprehensive error handling strategies, patterns, and best practices, see the Error Handling concepts page.