Navigation Menu

Skip to content

Commit

Permalink
A little pretty error page
Browse files Browse the repository at this point in the history
  • Loading branch information
darashi committed Aug 8, 2012
1 parent 3991ff9 commit f6f57ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/server.js
Expand Up @@ -20,6 +20,12 @@ if (!searchNode) {
// configuration
app.set('views', __dirname + '/../views');
app.use(express.static(__dirname + '/../public'));
app.use(app.router);

app.use(function(error, request, response, next){
response.status(error.status || 500);
response.render('error.jade', {message: error.message, query: error.query});
});

// helpers
function search(query, callback) {
Expand All @@ -28,6 +34,7 @@ function search(query, callback) {
var request = http.get(url, function(response) {
if (response.statusCode !== 200) {
var error = new Error('Search server returned ' + response.statusCode);
error.query = query;
return callback(error);
}

Expand All @@ -49,14 +56,13 @@ function search(query, callback) {
};

// routings
app.get('/', function(request, response){
app.get('/', function(request, response, next){
var query = request.query.query;
if (query) {
console.log('QUERY <' + query + '>');
search(query, function(error, results) {
if (error) {
// FIXME
return response.send(500, 'ERROR' + error);
return next(error);
}
var records = results.hits.hit;

Expand Down
6 changes: 6 additions & 0 deletions views/error.jade
@@ -0,0 +1,6 @@
extends layout

block content
.alert.alert-error
strong Error!
= message

0 comments on commit f6f57ed

Please sign in to comment.