app/App.js
/**
   *  Register the error handler which will catch errors and invoke the correct
   *  handler based on the error status
   *
   *  @return {void}
   */
Register the error handler which will catch errors and invoke the correct
handler based on the error status

@return {void}
Register the error handler which will catch errors and invoke the correct handler based on the error status @return { void }
registerErrorHandlers() {
    let handlers = {
          400: './ErrorHandlers/BadRequest.js',
          404: './ErrorHandlers/NotFound.js',
          405: './ErrorHandlers/MethodNotAllowed',
          409: './ErrorHandlers/ResourceConflict.js',
          500: './ErrorHandlers/ServerError.js'
        },
        defaultError = 500;
    this.getApp().use((err, req, res, next) => {
      let status = err.status !== undefined ? err.status : defaultError;
      if(Object.keys(handlers).indexOf(status.toString()) < 0) {
        status = defaultError;
      }
      let handlerClass = require(handlers[status]),
          handler = new handlerClass();
      handler.setServiceContainer(this.getServiceContainer());
      handler.setError(err);
      handler.setRequest(req).setResponse(res);
      if(res.headersSent === false) {
        handler.handle();
      }
      handler.log();
      next();
    });
  }
registerErrorHandlers ( ) { let handlers = { 400 : './ErrorHandlers/BadRequest.js' , 404 : './ErrorHandlers/NotFound.js' , 405 : './ErrorHandlers/MethodNotAllowed' , 409 : './ErrorHandlers/ResourceConflict.js' , 500 : './ErrorHandlers/ServerError.js' } , defaultError = 500 ; this . getApp ( ) . use ( ( err , req , res , next ) => { let status = err . status !== undefined ? err . status : defaultError ; if ( Object . keys ( handlers ) . indexOf ( status . toString ( ) ) < 0 ) { status = defaultError ; } let handlerClass = require ( handlers [ status ] ) , handler = new handlerClass ( ) ; handler . setServiceContainer ( this . getServiceContainer ( ) ) ; handler . setError ( err ) ; handler . setRequest ( req ) . setResponse ( res ) ; if ( res . headersSent === false ) { handler . handle ( ) ; } handler . log ( ) ; next ( ) ; } ) ; }
Register the error handler which will catch errors and invoke the correct
  handler based on the error status
Register the error handler which will catch errors and invoke the correct handler based on the error status