mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
refactored error-pages example
This commit is contained in:
parent
4f4987e9ea
commit
1ac18f7903
|
|
@ -8,8 +8,7 @@ require.paths.unshift(__dirname + '/../../support');
|
|||
|
||||
var express = require('./../../lib/express');
|
||||
|
||||
var app = express.createServer(),
|
||||
sys = require('sys');
|
||||
var app = express.createServer();
|
||||
|
||||
// Serve default connect favicon
|
||||
app.use(express.favicon());
|
||||
|
|
@ -50,7 +49,11 @@ function NotFound(path){
|
|||
Error.captureStackTrace(this, arguments.callee);
|
||||
}
|
||||
|
||||
sys.inherits(NotFound, Error);
|
||||
/**
|
||||
* Inherit from `Error.prototype`.
|
||||
*/
|
||||
|
||||
NotFound.prototype.__proto__ = Error.prototype;
|
||||
|
||||
// We can call app.error() several times as shown below.
|
||||
// Here we check for an instanceof NotFound and show the
|
||||
|
|
@ -62,12 +65,7 @@ sys.inherits(NotFound, Error);
|
|||
|
||||
app.error(function(err, req, res, next){
|
||||
if (err instanceof NotFound) {
|
||||
res.render('404.jade', {
|
||||
status: 404,
|
||||
locals: {
|
||||
error: err
|
||||
}
|
||||
});
|
||||
res.render('404.jade', { status: 404, error: err });
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
|
|
@ -77,12 +75,7 @@ app.error(function(err, req, res, next){
|
|||
// this demo, however you can choose whatever you like
|
||||
|
||||
app.error(function(err, req, res){
|
||||
res.render('500.jade', {
|
||||
status: 500,
|
||||
locals: {
|
||||
error: err
|
||||
}
|
||||
});
|
||||
res.render('500.jade', { status: 500, error: err });
|
||||
});
|
||||
|
||||
// Routes
|
||||
|
|
@ -92,7 +85,7 @@ app.get('/', function(req, res){
|
|||
});
|
||||
|
||||
app.get('/404', function(req, res){
|
||||
throw new NotFound;
|
||||
throw new NotFound(req.url);
|
||||
});
|
||||
|
||||
app.get('/500', function(req, res, next){
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user