feat(utils): Introduce promiseAll util (#5543)
This commit is contained in:
committed by
GitHub
parent
e4ce2f4e07
commit
f90ba02087
@@ -3,14 +3,11 @@ import { NextFunction, Request, RequestHandler, Response } from "express"
|
||||
type handler = (req: Request, res: Response) => Promise<void>
|
||||
|
||||
export const wrapHandler = (fn: handler): RequestHandler => {
|
||||
return (
|
||||
req: Request & { errors?: Error[] },
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
if (req?.errors?.length) {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const req_ = req as Request & { errors?: Error[] }
|
||||
if (req_?.errors?.length) {
|
||||
return res.status(400).json({
|
||||
errors: req.errors,
|
||||
errors: req_.errors,
|
||||
message:
|
||||
"Provided request body contains errors. Please check the data and retry the request",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user