mirror of
https://github.com/fosrl/pangolin.git
synced 2025-06-28 16:10:04 +02:00
started integrating auth with lucia
This commit is contained in:
parent
a33a8d7367
commit
fc5dca136f
20 changed files with 1341 additions and 61 deletions
23
server/middlewares/formatError.ts
Normal file
23
server/middlewares/formatError.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { ErrorRequestHandler, NextFunction, Response } from "express";
|
||||
import ErrorResponse from "@server/types/ErrorResponse";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import logger from "@server/logger";
|
||||
import environment from "@server/environment";
|
||||
|
||||
export const errorHandlerMiddleware: ErrorRequestHandler = (
|
||||
error,
|
||||
req,
|
||||
res: Response<ErrorResponse>,
|
||||
next: NextFunction,
|
||||
) => {
|
||||
logger.error(error);
|
||||
const statusCode = error.statusCode || HttpCode.INTERNAL_SERVER_ERROR;
|
||||
res?.status(statusCode).send({
|
||||
data: null,
|
||||
success: false,
|
||||
error: true,
|
||||
message: error.message || "Internal Server Error",
|
||||
status: statusCode,
|
||||
stack: environment.ENVIRONMENT === "prod" ? null : error.stack,
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue