api-timeout-hono
@rtorcato/api-timeout-hono is the Hono adapter for
api-timeout. It fails a request with 503 if downstream
handlers don't finish within a deadline.
Install
pnpm add @rtorcato/api-timeout @rtorcato/api-timeout-hono hono
hono is a peer dependency (^4) — you bring your own version.
Usage
import { timeoutMiddleware } from '@rtorcato/api-timeout-hono'
// Any request not answered within 5s gets a 503 error envelope.
app.use(timeoutMiddleware({ ms: 5000 }))
On timeout it responds 503 with the standard error envelope
{ error: 'ServiceUnavailableError', code: 'service_unavailable', message } from
api-errors. Non-timeout errors bubble up to Hono's onError
unchanged.
Related
- api-timeout — framework-agnostic core (
withTimeout, notes) - api-timeout-express — the Express adapter