mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-12 08:08:46 +08:00
format:format and fix code
This commit is contained in:
@@ -15,7 +15,7 @@ export const authMiddleware = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
): Promise<void | Response> => {
|
||||
if (req.path === "/user/login" || req.path === "/user/register") {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
export const errorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {
|
||||
interface CustomError extends Error {
|
||||
status?: number;
|
||||
}
|
||||
|
||||
export const errorHandler = (err: CustomError, req: Request, res: Response): void => {
|
||||
console.error(err);
|
||||
res.status(err.status || 500).json({
|
||||
success: false,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
export const validateRequest = (requiredParams: string[]) => {
|
||||
export const validateRequest = (
|
||||
requiredParams: string[]
|
||||
): ((req: Request, res: Response, next: NextFunction) => Response | void) => {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const missingParams = requiredParams.filter((param) => !req.query[param] && !req.body[param]);
|
||||
if (missingParams.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user