SDKsTypeScript SDKType Reference
Error Types
TypeScript SDK error class hierarchy with error codes, metadata, and handling patterns.
Error Types
The SDK provides a typed error hierarchy. Every error extends AvnologyIdError and includes structured metadata for programmatic handling.
Error hierarchy
AvnologyIdError
+-- AuthError
| +-- InvalidCredentialsError
| +-- AccountLockedError
| +-- AccountDisabledError
| +-- MfaRequiredError
| +-- InvalidCodeError
| +-- ExpiredFlowError
| +-- PasswordBreachedError
| +-- PasswordTooWeakError
| +-- DuplicateAccountError
| +-- RegistrationDisabledError
| +-- MethodDisabledError
| +-- MfaAlreadyEnrolledError
+-- OAuthError
| +-- InvalidGrantError
| +-- InvalidClientError
| +-- InvalidScopeError
| +-- InvalidRedirectUriError
| +-- ExpiredCodeError
| +-- DeviceFlowExpiredError
| +-- DeviceFlowDeniedError
| +-- InsufficientScopeError
+-- ApiError
| +-- NotFoundError
| +-- ForbiddenError
| +-- UnauthorizedError
| +-- ConflictError
| +-- ValidationError
| +-- DuplicateError
+-- RateLimitError
+-- NetworkError
+-- TimeoutErrorAvnologyIdError
Base class for all SDK errors.
class AvnologyIdError extends Error {
/** Machine-readable error code (e.g., "AVNOLOGY_AUTH_001") */
code: string;
/** HTTP status code (if applicable) */
statusCode: number | null;
/** Human-readable error message */
message: string;
/** Request ID for support debugging */
requestId: string | null;
/** Additional error details */
details: Record<string, unknown>;
}AuthError subtypes
InvalidCredentialsError
Thrown when the email/password combination is incorrect.
class InvalidCredentialsError extends AuthError {
code: "AVNOLOGY_AUTH_001";
statusCode: 401;
}AccountLockedError
Thrown when the account is temporarily locked due to too many failed login attempts.
class AccountLockedError extends AuthError {
code: "AVNOLOGY_AUTH_002";
statusCode: 423;
retryAfter: number; // Seconds until unlock
}MfaRequiredError
Thrown when the first authentication factor succeeded but MFA is required.
class MfaRequiredError extends AuthError {
code: "AVNOLOGY_AUTH_004";
statusCode: 403;
flowId: string; // Flow ID for MFA verification
availableMethods: MfaMethod[]; // ["totp", "webauthn", "recovery_code"]
}InvalidCodeError
Thrown when a verification code (TOTP, SMS, recovery, email) is incorrect.
class InvalidCodeError extends AuthError {
code: "AVNOLOGY_AUTH_006";
statusCode: 400;
attemptsRemaining: number; // Remaining attempts before lockout
}ValidationError
Thrown when request fields fail validation.
class ValidationError extends ApiError {
code: "AVNOLOGY_API_422";
statusCode: 422;
fieldErrors: FieldError[];
}
interface FieldError {
field: string; // "email", "traits.phone", "password"
message: string; // "Invalid email format"
code: string; // "invalid_format", "too_short", "required"
}RateLimitError
class RateLimitError extends AvnologyIdError {
code: "AVNOLOGY_API_429";
statusCode: 429;
retryAfter: number; // Seconds until rate limit resets
limit: number; // Request limit
remaining: number; // Remaining requests (always 0)
resetAt: string; // ISO 8601 reset time
}Error handling patterns
Catch specific errors
import {
InvalidCredentialsError,
MfaRequiredError,
RateLimitError,
} from "@avnology/sdk-typescript";
try {
await client.login({ email, password });
} catch (error) {
if (error instanceof InvalidCredentialsError) {
// Handle wrong credentials
} else if (error instanceof MfaRequiredError) {
// Handle MFA challenge
} else if (error instanceof RateLimitError) {
// Handle rate limit
} else {
// Unknown error
throw error;
}
}Check error code
import { AvnologyIdError } from "@avnology/sdk-typescript";
try {
await client.admin.getUser({ userId: "usr_nonexistent" });
} catch (error) {
if (error instanceof AvnologyIdError) {
switch (error.code) {
case "AVNOLOGY_API_404":
console.log("User not found");
break;
case "AVNOLOGY_API_403":
console.log("Permission denied");
break;
default:
console.log("Error:", error.code, error.message);
}
}
}Log errors with request ID
import { AvnologyIdError } from "@avnology/sdk-typescript";
try {
await someOperation();
} catch (error) {
if (error instanceof AvnologyIdError && error.requestId) {
console.error(
`Avnology ID error: ${error.code} (request: ${error.requestId})`
);
// Provide request ID to support for debugging
}
}Error code reference
| Code | Error class | Description |
|---|---|---|
AVNOLOGY_AUTH_001 | InvalidCredentialsError | Wrong email or password |
AVNOLOGY_AUTH_002 | AccountLockedError | Account temporarily locked |
AVNOLOGY_AUTH_003 | AccountDisabledError | Account administratively disabled |
AVNOLOGY_AUTH_004 | MfaRequiredError | MFA challenge required |
AVNOLOGY_AUTH_005 | ExpiredFlowError | Auth flow expired |
AVNOLOGY_AUTH_006 | InvalidCodeError | Wrong verification code |
AVNOLOGY_AUTH_007 | PasswordBreachedError | Password found in breach |
AVNOLOGY_AUTH_008 | PasswordTooWeakError | Password fails policy |
AVNOLOGY_AUTH_009 | DuplicateAccountError | Email already registered |
AVNOLOGY_AUTH_010 | RegistrationDisabledError | Registration not allowed |
AVNOLOGY_AUTH_011 | MethodDisabledError | Auth method disabled for org |
AVNOLOGY_AUTH_012 | MfaAlreadyEnrolledError | MFA method already set up |
AVNOLOGY_OAUTH_001 | InvalidGrantError | Invalid or expired grant |
AVNOLOGY_OAUTH_002 | InvalidClientError | Client auth failed |
AVNOLOGY_OAUTH_003 | InvalidScopeError | Scope not allowed |
AVNOLOGY_OAUTH_004 | DeviceFlowExpiredError | Device code expired |
AVNOLOGY_OAUTH_005 | DeviceFlowDeniedError | User denied device auth |
AVNOLOGY_OAUTH_006 | InsufficientScopeError | Missing required scope |
AVNOLOGY_API_401 | UnauthorizedError | Not authenticated |
AVNOLOGY_API_403 | ForbiddenError | Not authorized |
AVNOLOGY_API_404 | NotFoundError | Resource not found |
AVNOLOGY_API_409 | ConflictError | Resource conflict |
AVNOLOGY_API_422 | ValidationError | Validation failed |
AVNOLOGY_API_429 | RateLimitError | Rate limit exceeded |
See also
- Login -- Error handling in login flows
- Configuration -- Global error handler setup