Errors
Node.js SDK - Error handling and exception classes
Error Hierarchy
All SDK errors extend DocuTrayError:
DocuTrayError (base)
├── APIConnectionError (network errors)
│ └── APITimeoutError (request timeout)
└── APIError (HTTP errors)
├── 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 (error) {
if (error instanceof RateLimitError) {
console.log('Rate limited, retry after:', error.retryAfter);
} else if (error instanceof AuthenticationError) {
console.log('Invalid API key');
} else if (error instanceof APIError) {
console.log(error.statusCode, error.message, error.requestId);
} else if (error instanceof DocuTrayError) {
console.log('SDK error:', error.message);
}
}DocuTrayError
Base class for all SDK errors.
| Property | Type | Description |
|---|---|---|
message | string | Error description |
name | string | Error class name |
APIConnectionError
Thrown when the SDK cannot establish a connection to the API.
| Property | Type | Description |
|---|---|---|
cause | unknown | The underlying connection error |
APITimeoutError
Thrown when a request exceeds the configured timeout. Extends APIConnectionError.
APIError
Thrown when the API returns a non-success HTTP status code.
| Property | Type | Description |
|---|---|---|
statusCode | number | HTTP status code |
requestId | string | undefined | The x-request-id header |
body | unknown | Parsed response body |
headers | Headers | Raw response headers |
Status-Specific Errors
| Error Class | Status Code | 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 error |
RateLimitError
Includes rate-limit metadata 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 | Max requests in current window |
remaining | number | undefined | Requests remaining in window |
resetTime | Date | undefined | When the rate limit resets |