Skip to main content
Version: 0.1.22
Last Verified: 2025-01-27
Package: @hopx-ai/sdk on npm

Overview

The JavaScript SDK provides a comprehensive error hierarchy for handling different types of errors. All errors inherit from HopxError.

Import

Base Error

HopxError

Base exception for all HopX SDK errors. Properties:
  • message (string): Error message
  • code (string, optional): Error code
  • requestId (string, optional): Request ID for debugging
  • statusCode (number, optional): HTTP status code
  • details (Record<string, any>, optional): Additional error details

API Errors

APIError

Base class for API request failures. Inherits from: HopxError

AuthenticationError

Authentication failed (401). Inherits from: APIError When thrown:
  • Invalid or missing API key
  • Expired authentication token

NotFoundError

Resource not found (404). Inherits from: APIError When thrown:
  • Sandbox not found
  • Template not found
  • File not found

ValidationError

Request validation failed (400). Inherits from: APIError When thrown:
  • Invalid parameters
  • Missing required fields

RateLimitError

Rate limit exceeded (429). Inherits from: APIError Properties:
  • retryAfter (number, optional): Seconds to wait before retrying

ResourceLimitError

Resource limit exceeded. Inherits from: APIError Properties:
  • limit (number): Resource limit
  • current (number): Current usage
  • available (number): Available resources

ServerError

Server error (5xx). Inherits from: APIError

Network Errors

NetworkError

Network communication failed. Inherits from: HopxError

TimeoutError

Request timed out. Inherits from: NetworkError

Error Handling Examples

Example 1: Basic Error Handling

Example 2: Specific Error Handling


  • Types - TypeScript type definitions
  • Sandbox - Sandbox operations that may throw errors

See Also

Next Steps

Now that you understand error handling, explore: