Skip to main content
Openfuse
Guides

Check breaker state

Query breaker state for conditional logic and monitoring

The SDK provides methods to check breaker state directly. These are useful for conditional UI, health check endpoints, and monitoring.

isOpen / isClosed

if (await openfuse.breaker('stripe').isOpen()) {
  return cachedResponse
}

if (await openfuse.breaker('stripe').isClosed()) {
  // Stripe is healthy
}

Both return a Promise<boolean> and never throw. If the API is unreachable, they return safe defaults:

MethodSafe defaultReason
isOpen()falseFail-open: assume the service is healthy
isClosed()trueFail-open: assume the service is healthy

status

Returns the full breaker object or null:

const breaker = await openfuse.breaker('stripe').status()

if (breaker) {
  console.log(breaker.slug)       // 'stripe'
  console.log(breaker.state)      // 'open' | 'closed' | 'half-open'
  console.log(breaker.updatedAt)  // ISO-8601 timestamp or undefined
  console.log(breaker.retryAfter) // ISO-8601 timestamp or null
}

Returns null if the breaker isn't found or the API is unreachable. Never throws.

breakers

List all breakers for the configured system:

const allBreakers = await openfuse.breakers()

for (const breaker of allBreakers) {
  console.log(`${breaker.slug}: ${breaker.state}`)
}

Returns [] on any error. Never throws.

Prefer protect() over state checks

Don't use isOpen() to decide whether to call protect(). Use protect() with a fallback instead.

// Don't do this
if (await openfuse.breaker('stripe').isOpen()) {
  return fallbackValue
}
const result = await openfuse.breaker('stripe').protect(() => callStripe())

// Do this instead
const result = await openfuse.breaker('stripe').protect(
  () => callStripe(),
  { fallback: () => fallbackValue },
)

Use state checks for conditional UI, health endpoints, and logging.

Performance

State checks have a 500ms budget. If the API doesn't respond in time, the SDK returns the safe default immediately. The underlying request continues in the background to update the cache.

State is cached locally (3s TTL for API fetches, 30s TTL for bootstrap data), so most calls resolve from cache in microseconds.

On this page