feat: implement error handling and validation middleware, enhance result handling
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
20
apps/backend/src/lib/http/error-handler.ts
Normal file
20
apps/backend/src/lib/http/error-handler.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// http/error-handler.ts
|
||||
import type { MiddlewareHandler } from 'hono'
|
||||
import { unexpectedProblem } from './problem-builders'
|
||||
import { logger } from '../logger'
|
||||
|
||||
export const errorHandler: MiddlewareHandler = async (c, next) => {
|
||||
try {
|
||||
await next()
|
||||
} catch (error) {
|
||||
const requestId = c.get('requestId') as string | undefined
|
||||
const instance = requestId ? `/requests/${requestId}` : undefined
|
||||
|
||||
logger.error({
|
||||
requestId,
|
||||
error
|
||||
})
|
||||
|
||||
return c.json(unexpectedProblem({ instance }), 500)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user