import { BadRequestError , CallableStack , Interceptor , RestInterceptor } from '@libstack/server' ; import { ValidationError } from 'sequelize' ; import { Request , Response } from 'express' ; @ RestInterceptor class ValidationInterceptor implements Interceptor { intercepts ( parameters , request ) { return true ; } async execute ( parameters , req , res , stack ) { try { return await stack . next ( ) ; } catch ( err ) { if ( err instanceof ValidationError ) { const errors = { } ; for ( let error of err . errors ) { let field = errors [ error . path ] ; if ( ! field ) { field = [ ] ; errors [ error . path ] = field ; } field . push ( error . message ) ; } throw new BadRequestError ( 'Validation Problems' , { errors } ) ; } throw err ; } } }