Skip to content

Commit 14f8924

Browse files
authored
docs(exception): complete app.onError example with fallback for non-HTTPExceptions (#839)
1 parent 57268ca commit 14f8924

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

docs/api/exception.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,14 @@ import { HTTPException } from 'hono/http-exception'
6666

6767
// ...
6868

69-
app.onError((error, c) => {
70-
if (error instanceof HTTPException) {
71-
console.error(error.cause)
72-
// Get the custom response
73-
return error.getResponse()
69+
app.onError((err, c) => {
70+
if (err instanceof HTTPException) {
71+
// Return the error response generated by HTTPException
72+
return err.getResponse()
7473
}
75-
// ...
76-
// ---cut-start---
77-
return c.text('Unexpected error')
78-
// ---cut-end---
74+
// For any other unexpected errors, log and return a generic 500 response
75+
console.error(err)
76+
return c.text('Internal Server Error', 500)
7977
})
8078
```
8179

0 commit comments

Comments
 (0)