# Error Handling
Structured error responses for programmatic handling.
Error Codes
AUTHENTICATION_ERROR401VALIDATION_ERROR400POLICY_DENIED200THREAT_DETECTED200RATE_LIMIT_ERROR429NOT_FOUND404INTERNAL_ERROR500Error Handling Example
typescript
1import {2 APIError,3 AuthenticationError,4 RateLimitError,5 ValidationError6} from '@solongate/sdk';78try {9 const result = await api.validate('file_read', { path: '/data/file.txt' });10} catch (error) {11 if (error instanceof AuthenticationError) {12 console.error('Invalid API key');13 } else if (error instanceof RateLimitError) {14 console.error('Rate limited. Retry after:', error.retryAfter);15 } else if (error instanceof ValidationError) {16 console.error('Invalid request:', error.details);17 } else if (error instanceof APIError) {18 console.error('API error:', error.code, error.message);19 }20}
Error Response Format
json
1{2 "error": {3 "code": "AUTHENTICATION_ERROR",4 "message": "Invalid API key",5 "details": {6 "hint": "Check that your API key starts with 'sg_live_' or 'sg_test_'"7 }8 },9 "requestId": "req_abc123xyz"10}
Retry Strategy
typescript
1import { SolonGateAPI, RateLimitError } from '@solongate/sdk';23async function validateWithRetry(4 api: SolonGateAPI,5 tool: string,6 args: Record<string, any>,7 maxRetries = 38) {9 for (let i = 0; i < maxRetries; i++) {10 try {11 return await api.validate(tool, args);12 } catch (error) {13 if (error instanceof RateLimitError && i < maxRetries - 1) {14 // Wait for the retry-after period15 await new Promise(resolve =>16 setTimeout(resolve, error.retryAfter * 1000)17 );18 continue;19 }20 throw error;21 }22 }23}