Skip to content
Browse files

Initial

  • Loading branch information...
0 parents commit 478b385007db3c75c706063a4e2d96270ec3e4f3 @corpix committed Dec 1, 2011
Showing with 46 additions and 0 deletions.
  1. +46 −0 index.js
46 index.js
@@ -0,0 +1,46 @@
+module.exports = function(app, opts){
+
+ app.use(function(req, res, next){
+ next(new NotFound(req.url))
+ })
+
+ function NotFound(path){
+ this.name = 'NotFound'
+ if (path) {
+ Error.call(this, 'Cannot find ' + path)
+ this.path = path
+ } else {
+ Error.call(this, 'Not Found')
+ }
+ Error.captureStackTrace(this, arguments.callee)
+ }
+
+ NotFound.prototype.__proto__ = Error.prototype
+
+ app.error(function(err, req, res, next){
+ if (err instanceof NotFound){
+ if(req.xhr)
+ return res.send({}, 404)
+
+ res.render('errors/404', {
+ layout: opts.layout,
+ status: 404,
+ error: err,
+ showStack: app.settings.showStackError,
+ title: 'Oops! The page you requested desn\'t exist'
+ })
+ } else {
+ console.log(err.stack)
+ if(req.xhr)
+ return res.send({}, 500)
+ res.render('errors/500', {
+ layout: opts.layout,
+ status: 500,
+ error: err,
+ showStack: app.settings.showStackError,
+ title: 'Oops! Something went wrong!'
+ })
+ }
+ })
+
+}

0 comments on commit 478b385

Please sign in to comment.
Something went wrong with that request. Please try again.