Skip to main content
Openfuse
Reference

Error Classes

All error classes and the isServerOrNetworkError utility

All error classes are exported from the package root:

import {
  ConfigurationError,
  AuthError,
  APIError,
  NotFoundError,
  AbortOperationError,
  TimeoutError,
  isServerOrNetworkError,
} from '@openfuseio/sdk'

Overview

ErrorExtendsWhen thrown
ConfigurationErrorErrorConstructor called with missing or invalid options.
AuthErrorErrorAuthentication fails (invalid credentials or rejected token).
APIErrorErrorNon-auth HTTP errors from the Openfuse API (4xx/5xx).
NotFoundErrorErrorBreaker slug doesn't match any breaker in the system.
AbortOperationErrorErrorOperation cancelled via an AbortSignal.
TimeoutErrorErrorFunction wrapped by protect() exceeded its timeout.

ConfigurationError

class ConfigurationError extends Error {
  constructor(message: string)
  name: 'ConfigurationError'
}

Thrown when you pass missing or invalid options to the OpenfuseCloud or Openfuse constructor.

// Throws ConfigurationError
const client = new OpenfuseCloud({
  system: 'payments',
  clientId: '',
  clientSecret: 'secret',
})

AuthError

class AuthError extends Error {
  constructor(message: string)
  name: 'AuthError'
}

Thrown on invalid credentials during bootstrap or a rejected token refresh. Caught internally by init(), which logs the error and stops retrying. Never surfaced to your code from public methods.


APIError

class APIError extends Error {
  constructor(message: string, statusCode?: number)
  name: 'APIError'
  readonly statusCode?: number
}

Thrown when the Openfuse API returns a 4xx or 5xx response (excluding 401/403 which produce AuthError). Typically caught internally and handled via fail-open defaults.


NotFoundError

class NotFoundError extends Error {
  constructor(message: string)
  name: 'NotFoundError'
}

Thrown when the breaker slug doesn't match any breaker in the configured system. The SDK caches "not found" results for 60 seconds and logs a warning once every 5 minutes per slug.

Caught internally. isOpen(), isClosed(), and status() return safe defaults. protect() executes in fail-open mode.


AbortOperationError

class AbortOperationError extends Error {
  constructor(message?: string)
  name: 'AbortOperationError'
}

Thrown when a signal option is passed to protect() and the signal aborts before the function completes.

const controller = new AbortController()
controller.abort()

try {
  await stripe.protect(
    () => callStripe(),
    { signal: controller.signal },
  )
} catch (error) {
  // error instanceof AbortOperationError
}

TimeoutError

class TimeoutError extends Error {
  constructor(message?: string)
  name: 'TimeoutError'
}

Thrown when the timeout option is set on protect() and the wrapped function doesn't resolve in time.

try {
  await stripe.protect(
    () => slowOperation(),
    { timeout: 3000 },
  )
} catch (error) {
  // error instanceof TimeoutError
}

isServerOrNetworkError()

Classify errors as transient (safe to retry) or permanent.

function isServerOrNetworkError(error: unknown): boolean
InputReturnsReason
APIError with status >= 500trueServer error, transient
APIError with no statustrueNetwork error, transient
APIError with 4xx statusfalseClient error, not transient
NotFoundErrorfalseNot transient
Any other errortrueAssumed transient
import { isServerOrNetworkError } from '@openfuseio/sdk'

try {
  await stripe.protect(() => callExternalService())
} catch (error) {
  if (isServerOrNetworkError(error)) {
    // Safe to retry
  } else {
    // Fix the request
  }
}

On this page