export const errorHandler = (error, request, reply) => {
  request.log.error(error)

  if (error.validation) {
    return reply.code(422).send({
      success: false,
      error: { code: 'VALIDATION_ERROR', message: error.message },
    })
  }

  return reply.code(error.statusCode || 500).send({
    success: false,
    error: {
      code: error.code || 'INTERNAL_ERROR',
      message: error.message || 'An unexpected error occurred',
    },
  })
}
