lib/aonx.js
function _errorHandlers() {
  // middleware with an arity of 4 are considered
  // error handling middleware. When you next(err)
  // it will be passed through the defined middleware
  // in order, but ONLY those with an arity of 4, ignoring
  // regular middleware.
  app.use(function(err, req, res, next){
    logger.error(err);
    console.trace();
    if(req.accepts('html') || req.is('html')) {
      res.status(err.status || 500);
      res.render('500', { error: err });
      return;
    }
    res.send(err.status || 500, { error: err.message });
  });

  // our custom JSON 404 middleware. Since it's placed last
  // it will be the last middleware called, if all others
  // invoke next() and do not respond.
  app.use(function(req, res) {
    logger.error('Failed to locate:'+req.url);
    console.trace();
    if(req.accepts('html') || req.is('html')) {
      res.status(404);
      res.render('404', { url: req.url });
      return;
    }
    res.send(404, { error: "can't find the resource" });
  });
}
function _errorHandlers() {
  // middleware with an arity of 4 are considered
  // error handling middleware. When you next(err)
  // it will be passed through the defined middleware
  // in order, but ONLY those with an arity of 4, ignoring
  // regular middleware.
  app.use(function(err, req, res, next){
    logger.error(err);
    console.trace();
    if(req.accepts('html') || req.is('html')) {
      res.status(err.status || 500);
      res.render('500', { error: err });
      return;
    }
    res.send(err.status || 500, { error: err.message });
  });

  // our custom JSON 404 middleware. Since it's placed last
  // it will be the last middleware called, if all others
  // invoke next() and do not respond.
  app.use(function(req, res) {
    logger.error('Failed to locate:'+req.url);
    console.trace();
    if(req.accepts('html') || req.is('html')) {
      res.status(404);
      res.render('404', { url: req.url });
      return;
    }
    res.send(404, { error: "can't find the resource" });
  });
}
function _errorHandlers ( ) { // middleware with an arity of 4 are considered // error handling middleware. When you next(err) // it will be passed through the defined middleware // in order, but ONLY those with an arity of 4, ignoring // regular middleware. app . use ( function ( err , req , res , next ) { logger . error ( err ) ; console . trace ( ) ; if ( req . accepts ( 'html' ) || req . is ( 'html' ) ) { res . status ( err . status || 500 ) ; res . render ( '500' , { error : err } ) ; return ; } res . send ( err . status || 500 , { error : err . message } ) ; } ) ; // our custom JSON 404 middleware. Since it's placed last // it will be the last middleware called, if all others // invoke next() and do not respond. app . use ( function ( req , res ) { logger . error ( 'Failed to locate:' + req . url ) ; console . trace ( ) ; if ( req . accepts ( 'html' ) || req . is ( 'html' ) ) { res . status ( 404 ) ; res . render ( '404' , { url : req . url } ) ; return ; } res . send ( 404 , { error : "can't find the resource" } ) ; } ) ; }
register these error handlers in the express configuration
register these error handlers in the express configuration