/Knowledge/sources/honojs__hono/llms-full/timeout-middleware-usage--part-02--8639b987d502.md
Timeout Middleware: Usage (part 02) - hono-docs
Timeout Middleware: Usage (part 02) Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full.txt usage Summary ts i...
Timeout Middleware: Usage (part 02)
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#usage
Summary
```ts import { HTTPException } from 'hono/http-exception' // Custom exception factory function const customTimeoutException = (context) => new HTTPException(408, { message: `Request timeout after waiting ${context.req.headers.get( 'Durat...
Content
import { HTTPException } from 'hono/http-exception'
// Custom exception factory function
const customTimeoutException = (context) =>
new HTTPException(408, {
message: `Request timeout after waiting ${context.req.headers.get(
'Duration'
)} seconds. Please try again later.`,
})
// for Static Exception Message
// const customTimeoutException = new HTTPException(408, {
// message: 'Operation timed out. Please try again later.'
// });
// Applying a 1-minute timeout with a custom exception
app.use('/api/long-process', timeout(60000, customTimeoutException))
app.get('/api/long-process', async (c) => {
// Simulate a long process
await new Promise((resolve) => setTimeout(resolve, 61000))
return c.json({ data: 'This usually takes longer' })
})
Metadata
{
"chunk_index": 1,
"citation": "https://hono.dev/llms-full.txt#usage",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / Timeout Middleware > Usage (2)",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 349,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "Timeout Middleware: Usage (part 02)",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}