Skip to content

docs(exception): complete app.onError example with non-HTTPException fallback#839

Merged
yusukebe merged 1 commit intohonojs:mainfrom
ramanverse:fix/on-error-complete-example
Mar 19, 2026
Merged

docs(exception): complete app.onError example with non-HTTPException fallback#839
yusukebe merged 1 commit intohonojs:mainfrom
ramanverse:fix/on-error-complete-example

Conversation

@ramanverse
Copy link
Copy Markdown
Contributor

Problem

Fixes honojs/hono#2603

The app.onError example in docs/api/exception.md ended with a // ... placeholder, leaving readers with no guidance on how to handle errors that are not an HTTPException. The existing code also used internal twoslash ---cut-start---/---cut-end--- markers to hide the fallback from the rendered docs entirely.

Changes

File: docs/api/exception.md

  • Replaced the // ... placeholder and hidden twoslash cut blocks with a complete, visible fallback
  • Shows the recommended pattern: log unexpected errors with console.error(err) and return c.text('Internal Server Error', 500)
  • Renamed errorerr for consistency with Hono's codebase style

Before / After

Before:

app.onError((error, c) => {
  if (error instanceof HTTPException) {
    console.error(error.cause)
    return error.getResponse()
  }
  // ...
})

After:

app.onError((err, c) => {
  if (err instanceof HTTPException) {
    // Return the error response generated by HTTPException
    return err.getResponse()
  }
  // For any other unexpected errors, log and return a generic 500 response
  console.error(err)
  return c.text('Internal Server Error', 500)
})

Impact

Docs-only change. No source code or tests modified.

Copy link
Copy Markdown
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yusukebe
Copy link
Copy Markdown
Member

@ramanverse Thanks.

@yusukebe yusukebe merged commit 14f8924 into honojs:main Mar 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make a complete example of onError handling in the docs

2 participants