Error handling
import {
MineTechError, ApiError,
AuthenticationError, PermissionError, NotFoundError, ConflictError,
ValidationError, RateLimitError, ServerError,
ConnectionError, TimeoutError,
SignatureVerificationError, ConfigurationError,
} from '@minetech/node/errors';
| Class | Status | Retried |
|---|---|---|
ValidationError | 400, 422 | No |
AuthenticationError | 401 | No |
PermissionError | 403 | No |
NotFoundError | 404 | No |
ConflictError | 409 | No |
RateLimitError | 429 | Yes |
ServerError | 5xx | Yes |
TimeoutError | — | Yes |
ConnectionError | — | Yes |
ConfigurationError | — | Thrown at construction |
Every class is actually thrown by the SDK, and a test pins the status→class mapping —
an instanceof check that compiles will match at runtime.
Fields
catch (error) {
if (error instanceof ApiError) {
error.status; // 403
error.code; // 'insufficient_scope'
error.requestId; // quote this to support
error.body; // parsed response body
error.headers;
}
}
ValidationError adds fieldErrors; RateLimitError adds retryAfterSeconds.
Retries happen first
By the time an error reaches you, retryable failures have already been retried with
backoff and jitter. A ServerError in your catch means the server failed
repeatedly, not once.