Update error-handler.ts

This commit is contained in:
Daniel Hougaard
2024-09-19 20:06:19 +04:00
parent 862e2e9d65
commit f8161c8c72

View File

@@ -1,6 +1,6 @@
import { ForbiddenError } from "@casl/ability";
import fastifyPlugin from "fastify-plugin";
import { JsonWebTokenError } from "jsonwebtoken";
import jwt from "jsonwebtoken";
import { ZodError } from "zod";
import {
@@ -44,7 +44,7 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
detail: error.detail
});
// Handle JWT errors and make them more human-readable for the end-user.
} else if (error instanceof JsonWebTokenError) {
} else if (error instanceof jwt.JsonWebTokenError) {
const message = (() => {
if (error.message === JWTErrors.JwtExpired) {
return "Your token has expired. Please re-authenticate.";