import { Context } from 'hono'
import { z } from '@hono/zod-openapi'

export const ErrorSchema = z.object({
  code: z.number().openapi({
    example: 400,
  }),
  message: z.string().openapi({
    example: 'Bad Request',
  }),
})

export const errorHandler = async (err: Error, c: Context) => {
  return c.json(
    {
      code: 500,
      message: err.message || 'Internal Server Error'
    },
    500
  )
}