Error Types

The SDK provides specialized error classes for different error scenarios. All errors extend from SDKError.

SDKError (Base Class)

Base error class that all SDK errors extend from.

Properties:

  • message: string - Human-readable error message

  • code: string - Error code for programmatic handling

  • details?: any - Additional error context

AuthenticationError

Thrown when authentication fails.

Common Causes:

  • Invalid credentials

  • Expired tokens

  • Malformed JWT tokens

  • Invalid signature

Example:

import { AuthenticationError } from "yieldfi-sdk";

try {
  await sdk.auth.login(credentials);
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error("Auth failed:", error.message);
    console.error("Code:", error.code);
    console.error("Details:", error.details);
  }
}

NetworkError

Thrown for network-related errors.

Properties:

  • statusCode?: number - HTTP status code

  • response?: any - Response data (if available)

Common Causes:

  • Network connectivity issues

  • Request timeouts

  • HTTP errors (4xx, 5xx)

  • Server unavailable

Example:

ValidationError

Thrown when input validation fails.

Common Causes:

  • Missing required parameters

  • Invalid parameter types

  • Out-of-range values

  • Invalid format

Example:

ConfigurationError

Thrown when SDK configuration is invalid.

Common Causes:

  • Missing required configuration

  • Invalid configuration values

  • Invalid gateway URL format

Example:

Complete Error Handling Example

Error Codes

Common error codes you may encounter:

  • AUTH_FAILED - Authentication failed

  • TOKEN_EXPIRED - Token expired

  • INVALID_TOKEN - Invalid token format

  • NETWORK_ERROR - Network request failed

  • TIMEOUT - Request timeout

  • VALIDATION_ERROR - Input validation failed

  • NOT_FOUND - Resource not found

  • FORBIDDEN - Access forbidden

  • SERVER_ERROR - Server error

Last updated