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
| Error | Extends | When thrown |
|---|---|---|
ConfigurationError | Error | Constructor called with missing or invalid options. |
AuthError | Error | Authentication fails (invalid credentials or rejected token). |
APIError | Error | Non-auth HTTP errors from the Openfuse API (4xx/5xx). |
NotFoundError | Error | Breaker slug doesn't match any breaker in the system. |
AbortOperationError | Error | Operation cancelled via an AbortSignal. |
TimeoutError | Error | Function 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| Input | Returns | Reason |
|---|---|---|
APIError with status >= 500 | true | Server error, transient |
APIError with no status | true | Network error, transient |
APIError with 4xx status | false | Client error, not transient |
NotFoundError | false | Not transient |
| Any other error | true | Assumed transient |
import { isServerOrNetworkError } from '@openfuseio/sdk'
try {
await stripe.protect(() => callExternalService())
} catch (error) {
if (isServerOrNetworkError(error)) {
// Safe to retry
} else {
// Fix the request
}
}