import { Request , Response , NextFunction } from "express" ; import { default as HttpErrorsList } from "./errorsList" ; import { default as Merror } from "./merrorConstructor" ; import { HttpErrorItem } from "./types" ; param { Merror } err param { Request } req param { Response } res param { NextFunction } next returns { void } export function MerrorHandler ( err , req , res , next ) { if ( err . isHttpError ) { const errorItem = HttpErrorsList . find ( ( errorItem ) => parseInt ( errorItem . code ) === err . statusCode ) ; if ( errorItem ) { res . status ( err . statusCode ) . send ( { "success" : false , "statusCode" : err . statusCode , "error" : errorItem . phrase , "message" : err . message , "properties" : err . properties } ) ; } else { return next ( new Error ( "There's no HTTP error with provided statusCode" ) ) ; } } return next ( err ) ; } returns { void } export function MerrorMiddleware ( ) { return MerrorHandler ; } export { default as HttpErrorsList } from "./errorsList" ; export { default as Merror } from "./merrorConstructor" ; export { HttpErrorItem , ErrorNumber } from "./types" ;