Errors
Error hierarchy for error handling in the DocuTray Node.js SDK
Error Hierarchy
All errors thrown by the SDK extend DocuTrayError. API errors include HTTP status code information and response details.
DocuTrayError
├── APIConnectionError
│ └── APITimeoutError
└── APIError
├── BadRequestError (400)
├── AuthenticationError (401)
├── PermissionDeniedError (403)
├── NotFoundError (404)
├── ConflictError (409)
├── UnprocessableEntityError (422)
├── RateLimitError (429)
└── InternalServerError (5xx)Usage
import DocuTray, {
DocuTrayError,
APIError,
AuthenticationError,
RateLimitError,
} from 'docutray';
const client = new DocuTray();
try {
await client.convert.run({ documentTypeCode: 'invoice', url: '...' });
} catch (err) {
if (err instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${err.retryAfter}s`);
} else if (err instanceof AuthenticationError) {
console.log('Invalid API key');
} else if (err instanceof APIError) {
console.log(`API error ${err.statusCode}: ${err.message}`);
console.log('Request ID:', err.requestId);
} else if (err instanceof DocuTrayError) {
console.log('SDK error:', err.message);
}
}DocuTrayError
Base error class for all SDK errors.
| Property | Type | Description |
|---|---|---|
message | string | Error message |
name | string | Error class name |
APIConnectionError
Thrown when the SDK cannot establish a connection to the API.
| Property | Type | Description |
|---|---|---|
cause | unknown | The underlying error that caused the connection failure |
APITimeoutError
Thrown when a request exceeds the configured timeout or is aborted. Extends APIConnectionError.
APIError
Thrown when the API returns a non-success HTTP status code.
| Property | Type | Description |
|---|---|---|
statusCode | number | The HTTP status code |
requestId | string | undefined | The x-request-id header value |
body | unknown | The parsed response body |
headers | Headers | The raw response headers |
Status-Specific Errors
| Error Class | HTTP Status | Description |
|---|---|---|
BadRequestError | 400 | Invalid request parameters |
AuthenticationError | 401 | Invalid or missing API key |
PermissionDeniedError | 403 | Insufficient permissions |
NotFoundError | 404 | Resource not found |
ConflictError | 409 | Resource conflict |
UnprocessableEntityError | 422 | Validation errors |
RateLimitError | 429 | Rate limit exceeded |
InternalServerError | 5xx | Server-side errors |
RateLimitError
Includes additional rate-limit metadata extracted from response headers.
| Property | Type | Description |
|---|---|---|
retryAfter | number | undefined | Seconds to wait before retrying |
limitType | string | undefined | Type of rate limit hit |
limit | number | undefined | Maximum requests allowed in current window |
remaining | number | undefined | Requests remaining in current window |
resetTime | Date | undefined | When the rate limit window resets |