@inialum/error-notification-service-hono-middleware
v0.4.1
Published
Hono middleware for inialum-error-notification-service
Downloads
82
Readme
@inialum/error-notification-service-hono-middleware
Hono middleware for inialum-error-notification-service.
Installation
pnpm add @inialum/error-notification-service-hono-middlewareUsage
import { Hono } from 'hono'
import { notifyError } from '@inialum/error-notification-service-hono-middleware'
const app = new Hono()
app.use(
'*',
notifyError({
token: 'dummy',
serviceName: 'service-name',
environment: 'production',
enabled: true, // Optional
ignoreErrors: ['ValidationError', 'NotFoundError'], // Optional
beforeSend: (error, payload) => {
// Modify the error payload or cancel sending
if (error.message.includes('sensitive')) {
// Don't send errors with sensitive information
return null
}
// Add request information to the description
payload.description = `${payload.description} (Request ID: req-123)`
return payload
},
}),
)
app.get('/', (c) => c.text('foo'))
export default appYou can refer to the example project for more details.
Options
| Option | Type | Required | Description |
| -------------- | -------- | -------- | ----------------------------------------------------------------------------- |
| token | string | Yes | Authentication token for the error notification service |
| serviceName | string | Yes | Name of the service reporting the error |
| environment | string | Yes | Environment where the error occurred (e.g., 'local', 'staging', 'production') |
| enabled | boolean | No | Whether error notifications are enabled (default: true) |
| ignoreErrors | string[] | No | List of error names to ignore |
| beforeSend | function | No | Function to modify error data before sending or cancel sending |
beforeSend Function
The beforeSend function allows you to:
- Modify error data before it's sent to the notification service
- Prevent sending certain errors by returning
nullorfalse
beforeSend: (error: Error, payload: ErrorNotificationPayload) => {
// Modify payload properties
payload.title = `[App] ${payload.title}`
// Add context to description
payload.description = `${payload.description}\nUser: ${currentUser}`
// Return modified payload to send it
return payload
// Or return null/false to cancel sending
// return null;
}Development
Testing
pnpm run testIf you want to run test with coverage report, run this command instead
pnpm run test:coverageLicense
Licensed under Apache License 2.0.
