import { NextApiRequest, NextApiResponse } from "next"
import logging from "../logging"

export default function sendError<T>(
  req: NextApiRequest,
  res: NextApiResponse<T>,
  err: any
) {
  // If something went wrong, let the client know with status 500
  res.status(err.statusCode ?? 500).end()
  logging(err.message, [err.type ?? (err.solved ? "debug" : "error")], req)
}
