17 lines
474 B
TypeScript
17 lines
474 B
TypeScript
import { Request, Response, NextFunction } from 'express'
|
|
import { validationResult } from 'express-validator'
|
|
import { Err } from '../services/globalService'
|
|
|
|
class Middleware {
|
|
handleValidationError(req: Request, res: Response, next: NextFunction) {
|
|
const error = validationResult(req)
|
|
if (!error.isEmpty()) {
|
|
new Err(400, error)
|
|
return res.status(400).json(new Err(400, 'validation error', error.array()[0]))
|
|
}
|
|
next()
|
|
}
|
|
}
|
|
|
|
export default new Middleware()
|