@shadmanZero/tenantos-api
    Preparing search index...

    Class TenantosApiError

    Thrown when the API returns an error response (4xx or 5xx status codes)

    This is the primary error class for HTTP-level API errors. It provides detailed information about the failed request including status code, response data, and request tracking information.

    The class includes helper methods for classifying different types of API errors and generating user-friendly error messages based on common HTTP status codes.

    try {
    await client.servers.get(999);
    } catch (error) {
    if (error instanceof TenantosApiError) {
    console.log(`Status: ${error.statusCode}`);
    console.log(`Message: ${error.message}`);
    console.log(`Request ID: ${error.requestId}`);

    if (error.isNotFound()) {
    console.log('Resource not found');
    } else if (error.isServerError()) {
    console.log('Server-side error occurred');
    }
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new TenantosApiError instance

      Parameters

      • message: string

        Error message from the API or a descriptive message

      • statusCode: number

        HTTP status code from the response

      • Optionalresponse: unknown

        Raw response data from the API (optional)

      • OptionalrequestId: string

        Unique request identifier for tracking (optional)

      • Optionaloptions: { cause?: Error }

        Additional error options including cause chaining

      Returns TenantosApiError

    Properties

    name: string = 'TenantosApiError'
    requestId?: string

    Unique request identifier for tracking (optional)

    response?: unknown

    Raw response data from the API (optional)

    statusCode: number

    HTTP status code from the response

    Methods

    • Get a user-friendly error message based on the HTTP status code

      This method provides human-readable error messages for common HTTP status codes, making it easier to display meaningful error information to users.

      Returns string

      A user-friendly error message string

      try {
      await client.servers.get(999);
      } catch (error) {
      if (error instanceof TenantosApiError) {
      alert(error.getUserMessage()); // Shows user-friendly message
      }
      }
    • Check if this is a client error (4xx status codes)

      Client errors indicate issues with the request such as invalid parameters, authentication failures, or requesting non-existent resources.

      Returns boolean

      True if the status code is in the 4xx range

      if (error.isClientError()) {
      console.log('Request error - check your parameters');
      }
    • Check if this is a server error (5xx status codes)

      Server errors indicate issues on the TenantOS server side and are typically temporary. These errors may be retryable depending on the specific status code.

      Returns boolean

      True if the status code is in the 5xx range

      if (error.isServerError()) {
      console.log('Server error - may be temporary, consider retrying');
      }
    • Check if this error has a specific HTTP status code

      Parameters

      • code: number

        The HTTP status code to check for

      Returns boolean

      True if the error status matches the provided code

      if (error.isStatus(404)) {
      console.log('Resource not found');
      } else if (error.isStatus(429)) {
      console.log('Rate limit exceeded');
      }