errorHandler.ts 434 B

1234567891011121314151617181920212223
  1. import { Context } from 'hono'
  2. import { HTTPException } from 'hono/http-exception'
  3. export const errorHandler = async (err: Error, c: Context) => {
  4. if (err instanceof HTTPException) {
  5. return c.json(
  6. {
  7. error: err.message,
  8. status: err.status ,
  9. cause: err.cause
  10. },
  11. err.status
  12. )
  13. }
  14. return c.json(
  15. {
  16. error: 'Internal Server Error',
  17. status: 500
  18. },
  19. 500
  20. )
  21. }