Errors
The error hierarchy in the BimpeAI TypeScript SDK and the extra fields on each error type.
Every error the SDK throws extends BimpeAIError. A UserError means the SDK rejected something before sending it, such as a missing API key. A request that never produced a response throws ConnectionError, and a timeout throws ConnectionTimeoutError, which extends it. Everything the server returned as an error extends ApiError.
import { RateLimitError, ValidationError } from '@bimpeai/sdk';
try {
await bimpe.agents.create({ name: '' });
} catch (error) {
if (error instanceof ValidationError) {
for (const field of error.fieldErrors) console.warn(`${field.path}: ${field.message}`);
} else if (error instanceof RateLimitError) {
console.warn(`retry in ${error.retryAfter}s`);
} else {
throw error;
}
}Hierarchy
BimpeAIError
├── UserError
├── ConnectionError
│ └── ConnectionTimeoutError
└── ApiError
├── BadRequestError
│ └── ValidationError
├── AuthenticationError
├── PermissionDeniedError
├── NotFoundError
├── ConflictError
├── RateLimitError
├── InternalServerError
└── NotImplementedErrorApiError fields
Every ApiError carries status, code, requestId, headers, and the raw body. code is one of the ErrorCode values (validation_error, bad_request, unauthorized, api_key_missing, api_key_invalid, api_key_expired, insufficient_scope, forbidden, not_found, conflict, rate_limited, too_many_requests, not_implemented, agent_limit_reached, internal_error), or null if the server sent none.
ValidationError
ValidationError adds fieldErrors, an array of { path, message } objects.
RateLimitError
RateLimitError adds retryAfter (seconds until the window resets), limit, remaining, and resetAt (a Date), read from the Retry-After and X-RateLimit-* response headers.