Skip to main content

NFCPaymentError

Thrown by NFC operations when something goes wrong at the device/hardware layer.
class NFCPaymentError extends Error {
  name: 'NFCPaymentError';
  code: NFCErrorCode;
  message: string;
}

NFCErrorCode

enum NFCErrorCode {
  NOT_SUPPORTED  = 'NFC_NOT_SUPPORTED',   // No NFC hardware
  NOT_ENABLED    = 'NFC_NOT_ENABLED',     // NFC disabled in settings
  READ_FAILED    = 'READ_FAILED',         // Hardware read failure
  WRITE_FAILED   = 'WRITE_FAILED',        // HCE emulation failed
  INVALID_DATA   = 'INVALID_DATA',        // Bad/expired/forged payload
  USER_CANCELLED = 'USER_CANCELLED',      // User dismissed NFC sheet
  API_ERROR      = 'API_ERROR',           // Backend error in NFC flow
  NETWORK_ERROR  = 'NETWORK_ERROR',       // No connection in NFC flow
  TIMEOUT        = 'TIMEOUT',            // 30s scan timeout
  UNAUTHORIZED   = 'UNAUTHORIZED',        // Invalid API key
}

Type guard

import { NFCPaymentError, NFCErrorCode } from '@taprails/tap-to-pay';

if (err instanceof NFCPaymentError) {
  switch (err.code) {
    case NFCErrorCode.TIMEOUT:
      // ...
  }
}

APIError

Thrown by the API client layer for backend communication failures.
class APIError extends Error {
  name: 'APIError';
  code: APIErrorCode;
  statusCode?: number;                // HTTP status code, if available
  details?: Record<string, any>;     // Extra context from the API response
  message: string;
}

APIErrorCode

enum APIErrorCode {
  NETWORK_ERROR       = 'NETWORK_ERROR',        // No connection / DNS failure
  TIMEOUT             = 'TIMEOUT',              // Request exceeded 30s
  UNAUTHORIZED        = 'UNAUTHORIZED',          // 401
  BAD_REQUEST         = 'BAD_REQUEST',           // 400
  NOT_FOUND           = 'NOT_FOUND',             // 404
  SERVER_ERROR        = 'SERVER_ERROR',          // 5xx
  UNKNOWN_ERROR       = 'UNKNOWN_ERROR',         // Unexpected
  SDK_NOT_INITIALIZED = 'SDK_NOT_INITIALIZED',  // initialize() not called
}

Type guard

import { APIError, APIErrorCode } from '@taprails/tap-to-pay';

if (err instanceof APIError) {
  if (err.code === APIErrorCode.UNAUTHORIZED) {
    redirectToLogin();
  }
}

APIErrorResponse

Raw error shape returned by the API:
interface APIErrorResponse {
  error: {
    code: string;
    message: string;
    details?: Record<string, any>;
  };
}