Skip to content

Commit

Permalink
added trace to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
truepattern committed Jul 12, 2012
1 parent bfa079e commit 4263d89
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
3 changes: 2 additions & 1 deletion History.md
@@ -1,5 +1,6 @@
# release 0.4.1
# release 0.4.2
* added support for clustering
* added trace on console for errors
# release 0.3.3
* added support for authentication (mongoose-auth) plugins based off of mongoose
* added https support, two additional params config.server.scheme = 'https' and config.server.key and config.server.cert (filenames)
Expand Down
35 changes: 19 additions & 16 deletions lib/aonx.js
Expand Up @@ -62,6 +62,7 @@ exports.init = function(appconfig, preHandler) {
// that if https is set, all the redirects
// would not go to https, fixing
// the variable req.secure to force 'https'
app.settings['trust proxy']=config.server.proxy || true;
if(config.server.scheme==='https') {
app.use(function(req,res,next) {
req.secure=true;
Expand Down Expand Up @@ -255,25 +256,27 @@ function _errorHandlers() {
// in order, but ONLY those with an arity of 4, ignoring
// regular middleware.
app.use(function(err, req, res, next){
winston.error(err);
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 });
});
winston.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) {
winston.error('Failed to locate:'+req.url);
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" });
});
winston.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" });
});
}
1 change: 1 addition & 0 deletions lib/config.js
Expand Up @@ -22,6 +22,7 @@ config.api.keycheck = false;
// --- server related settings
config.server = {};
config.server.port = process.env.PORT || 8074;
config.server.proxy = true;
config.server.modules = [];

// jsonp:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "aonx",
"description": "very opinionated application framework",
"homepage": "https://github.com/truepattern/aonx",
"version": "0.4.1",
"version": "0.4.2",
"author": "truepattern <admin@truepattern.com>",
"dependencies": {
"winston" : ">= 0.6.2",
Expand Down

0 comments on commit 4263d89

Please sign in to comment.