Changed "pages" example to show error() handlers defined above routes

This commit is contained in:
Tj Holowaychuk 2010-08-06 09:01:09 -07:00
parent ae5b0dbc29
commit c145a8e1a1

View File

@ -20,22 +20,14 @@ function NotFound(msg){
sys.inherits(NotFound, Error);
app.get('/', function(req, res){
res.render('index.jade');
});
app.get('/404', function(req, res){
throw new NotFound;
});
app.get('/500', function(req, res){
throw new Error('keyboard cat!');
});
// We can call app.error() several times as shown below.
// Here we check for an instanceof NotFound and show the
// 404 page, or we pass on to the next error handler.
// These handlers could potentially be defined within
// configure() blocks to provide introspection when
// in the development environment.
app.error(function(err, req, res, next){
if (err instanceof NotFound) {
res.render('404.jade');
@ -55,4 +47,18 @@ app.error(function(err, req, res){
});
});
// Routes
app.get('/', function(req, res){
res.render('index.jade');
});
app.get('/404', function(req, res){
throw new NotFound;
});
app.get('/500', function(req, res){
throw new Error('keyboard cat!');
});
app.listen(3000);