Bridge SDK

Errors

Structured error classes for bridge communication failures.

Error Classes

All errors extend BridgeError and include a code field for programmatic handling.

Hierarchy

BridgeError
├── BridgeApiError          — HTTP non-2xx response
├── BridgeConnectError      — WebSocket connection failure
├── BridgeValidationError   — Invalid input parameter
└── BridgeTimeoutError      — Operation timed out

BridgeError

Base class for all bridge errors.

class BridgeError extends Error {
  readonly code: string
}

BridgeApiError

Thrown when the REST API returns a non-2xx status.

class BridgeApiError extends BridgeError {
  readonly status: number           // HTTP status code
  readonly method: string           // 'GET', 'POST', etc.
  readonly path: string             // request path
  readonly body: string             // response body
  readonly responseJson?: unknown   // parsed JSON if available
}

Example:

try {
  await api.getSession('nonexistent')
} catch (err) {
  if (err instanceof BridgeApiError && err.status === 404) {
    console.log('Session not found')
  }
}

BridgeConnectError

Thrown when WebSocket connection fails.

class BridgeConnectError extends BridgeError {
  declare readonly cause: unknown
}

BridgeValidationError

Thrown for invalid parameters before making a request.

class BridgeValidationError extends BridgeError {
  readonly field: string   // which parameter is invalid
}

BridgeTimeoutError

Thrown when an operation exceeds its timeout.

class BridgeTimeoutError extends BridgeError {
  readonly operation: string    // what timed out
  readonly timeoutMs: number   // the timeout that was exceeded
}