Skip to main content
All SDK functions throw APIError instances with structured metadata for error handling.

Import

import { APIError } from "@paxoslabs/amplify-sdk";

APIError Class

class APIError extends Error {
  /** Error code for programmatic handling */
  code: string;

  /** SDK function that threw the error */
  endpoint: string;

  /** HTTP status code (if applicable) */
  statusCode?: number;

  /** Original error message */
  message: string;
}

Usage

import { APIError, prepareDepositAuthorization } from "@paxoslabs/amplify-sdk";

try {
  const auth = await prepareDepositAuthorization(params);
} catch (error) {
  if (error instanceof APIError) {
    console.log(error.code);       // "VAULT_NOT_FOUND"
    console.log(error.endpoint);   // "prepareDepositAuthorization"
    console.log(error.statusCode); // 404
    console.log(error.message);    // "No vault matches the provided parameters"
  }
}

Error Codes

Initialization Errors

CodeDescriptionResolution
SDK_NOT_INITIALIZEDSDK function called before initAmplifySDK()Call initAmplifySDK() at app startup
INVALID_API_KEYAPI key validation failedCheck key format (pxl_...)

Deposit Errors

CodeDescriptionResolution
VAULT_NOT_FOUNDNo vault matches yieldType, token, and chainIdVerify parameters with fetchSupportedAssets()
PERMIT_NOT_SUPPORTEDToken doesn’t support EIP-2612 permitsUse approval flow or forceMethod: "approval"
INSUFFICIENT_ALLOWANCEApproval amount insufficient for depositIncrease approval or use permit flow
INVALID_DEPOSIT_AMOUNTAmount is zero, negative, or malformedProvide valid decimal string (e.g., “100.25”)

Withdrawal Errors

CodeDescriptionResolution
VAULT_NOT_FOUNDNo vault matches parametersVerify yieldType and wantAssetAddress
INSUFFICIENT_SHARESUser doesn’t have enough vault sharesCheck share balance before withdrawing
LIQUIDITY_UNAVAILABLEVault has insufficient liquidityTry smaller amount or wait

Network Errors

CodeDescriptionResolution
NETWORK_ERRORFailed to connect to RPC or APICheck network connection and RPC URL
TIMEOUTRequest timed outRetry with backoff

Error Handling Patterns

Basic Error Handling

try {
  const auth = await prepareDepositAuthorization(params);
} catch (error) {
  if (error instanceof APIError) {
    switch (error.code) {
      case "SDK_NOT_INITIALIZED":
        await initAmplifySDK(apiKey);
        // Retry operation
        break;
      case "VAULT_NOT_FOUND":
        showError("This token is not supported for the selected yield type");
        break;
      default:
        showError(error.message);
    }
  }
}

Logging Errors

try {
  const prepared = await prepareDeposit(params);
} catch (error) {
  if (error instanceof APIError) {
    // Log structured error data
    console.error({
      code: error.code,
      endpoint: error.endpoint,
      statusCode: error.statusCode,
      message: error.message,
    });

    // Send to error tracking service
    errorTracker.capture(error, {
      extra: {
        endpoint: error.endpoint,
        statusCode: error.statusCode,
      },
    });
  }
}

User-Friendly Messages

function getErrorMessage(error: APIError): string {
  const messages: Record<string, string> = {
    SDK_NOT_INITIALIZED: "Please wait while we initialize...",
    VAULT_NOT_FOUND: "This token is not available for the selected strategy.",
    PERMIT_NOT_SUPPORTED: "Please approve the transaction in your wallet.",
    INSUFFICIENT_ALLOWANCE: "Please approve a higher amount.",
    LIQUIDITY_UNAVAILABLE: "Withdrawals are temporarily limited. Please try a smaller amount.",
  };

  return messages[error.code] || error.message;
}