Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nakasyou/hono-middleware-error-handler
Catch server error middleware for Hono.
https://github.com/nakasyou/hono-middleware-error-handler
Last synced: 3 days ago
JSON representation
Catch server error middleware for Hono.
- Host: GitHub
- URL: https://github.com/nakasyou/hono-middleware-error-handler
- Owner: nakasyou
- License: mit
- Created: 2023-08-23T12:03:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-11T13:47:09.000Z (about 1 year ago)
- Last Synced: 2024-10-11T17:43:53.992Z (27 days ago)
- Language: TypeScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hono-middleware-error-handler
Catch server error middleware for Hono.
## How to use it?
```ts
import { Hono } from 'https://deno.land/x/hono/mod.ts'
import { errorHandlerMiddleware } from 'https://deno.land/x/hono_middleware_error_handler/mod.ts'const app = new Hono()
app.use('/*', errorHandlerMiddleware())
app.get('/error', c => {
throw new Error('This is test error')
return c.text('Hello world!')
})Deno.serve(app.fetch)
```
If you send get request `/error`, you see this response.
```
Error: This is test error(...stack)
```
### Details
Other response:
```ts
errorHandlerMiddleware({
type: 'text' // Text Error Handler (default)
})
errorHandlerMiddleware({
type: 'html' // HTML Error Handler
})
errorHandlerMiddleware({
type: 'json' // JSON Error Handler
})
```
Custom transform:
```ts
errorHandlerMiddleware({
transform: ({
type, // Init type ('text', 'html', 'json')
error // Error object
}): string => {
return error.name
}
})
```