import { Token } from "@prisma/client"

export default async function jwtVerifyCatch(
  tokenType: Token["type"],
  err: Error
) {
  switch (err.message) {
    case "jwt expired":
      return {
        message: `JWT (${tokenType}) expired!`,
        statusCode: 403,
        solved: true,
        type: "warn",
      }

    case "invalid signature":
      return {
        message: `Invalid JWT (${tokenType}) signature! Token: `,
        statusCode: 401,
        solved: true,
        type: "error",
      }

    case "jwt must be provided":
      return {
        message: `No JWT (${tokenType}) given.`,
        statusCode: 401,
        solved: true,
        type: "warn",
      }

    default:
      console.log(err)
      return { message: `Unknown error on 'JWT.verify()'.`, solved: false }
  }
}
