Drizzle error instance

Is there a Drizzle error type that i can use for my Fastify global error handler ?? What im looking for is maybe something like the prisma error type Prisma.PrismaClientKnownRequestError, And what i want is to identify the drizzle error so i can handle them properly. this is how my global error handler looks :
export default function globalErrorHandler(
this: any,
error: FastifyError,
_req: FastifyRequest,
rep: FastifyReply
) {
this.log.error(error);

let statusCode = 500;
let message = "Internal server error";

switch (true) {
case error instanceof HttpError:
statusCode = error.status;
message = error.message;
break;

case error instanceof Error:
statusCode = error.statusCode ?? statusCode;
message = error.message;
break;

default:
break;
}

rep.code(statusCode).send({ message: message, success: false });
}
export default function globalErrorHandler(
this: any,
error: FastifyError,
_req: FastifyRequest,
rep: FastifyReply
) {
this.log.error(error);

let statusCode = 500;
let message = "Internal server error";

switch (true) {
case error instanceof HttpError:
statusCode = error.status;
message = error.message;
break;

case error instanceof Error:
statusCode = error.statusCode ?? statusCode;
message = error.message;
break;

default:
break;
}

rep.code(statusCode).send({ message: message, success: false });
}
If there is a better way to handler db errors that i can use please tell me
3 Replies
Luxaritas
Luxaritas14mo ago
I believe DB errors come from the underlying DB driver, not Drizzle
Luxaritas
Luxaritas14mo ago
Yeah
Want results from more Discord servers?
Add your server