Avnology ID
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
 +-- TimeoutError

AvnologyIdError

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

CodeError classDescription
AVNOLOGY_AUTH_001InvalidCredentialsErrorWrong email or password
AVNOLOGY_AUTH_002AccountLockedErrorAccount temporarily locked
AVNOLOGY_AUTH_003AccountDisabledErrorAccount administratively disabled
AVNOLOGY_AUTH_004MfaRequiredErrorMFA challenge required
AVNOLOGY_AUTH_005ExpiredFlowErrorAuth flow expired
AVNOLOGY_AUTH_006InvalidCodeErrorWrong verification code
AVNOLOGY_AUTH_007PasswordBreachedErrorPassword found in breach
AVNOLOGY_AUTH_008PasswordTooWeakErrorPassword fails policy
AVNOLOGY_AUTH_009DuplicateAccountErrorEmail already registered
AVNOLOGY_AUTH_010RegistrationDisabledErrorRegistration not allowed
AVNOLOGY_AUTH_011MethodDisabledErrorAuth method disabled for org
AVNOLOGY_AUTH_012MfaAlreadyEnrolledErrorMFA method already set up
AVNOLOGY_OAUTH_001InvalidGrantErrorInvalid or expired grant
AVNOLOGY_OAUTH_002InvalidClientErrorClient auth failed
AVNOLOGY_OAUTH_003InvalidScopeErrorScope not allowed
AVNOLOGY_OAUTH_004DeviceFlowExpiredErrorDevice code expired
AVNOLOGY_OAUTH_005DeviceFlowDeniedErrorUser denied device auth
AVNOLOGY_OAUTH_006InsufficientScopeErrorMissing required scope
AVNOLOGY_API_401UnauthorizedErrorNot authenticated
AVNOLOGY_API_403ForbiddenErrorNot authorized
AVNOLOGY_API_404NotFoundErrorResource not found
AVNOLOGY_API_409ConflictErrorResource conflict
AVNOLOGY_API_422ValidationErrorValidation failed
AVNOLOGY_API_429RateLimitErrorRate limit exceeded

See also

On this page