Skip to content
Browse files

Added plain option and view engine existense detection

  • Loading branch information...
1 parent ed0ed33 commit ce8b26a14aa8b7e0c1fe52ce3930bd69b4172f16 @corpix committed Feb 3, 2012
Showing with 19 additions and 10 deletions.
  1. +18 −9 index.js
  2. +1 −1 package.json
View
27 index.js
@@ -22,6 +22,12 @@ ex.define = function(opts){
}
ex.bind = function(app, opts){
+ if(!opts)
+ opts = {};
+
+ if(!app.set('view engine')){
+ opts.plain = true;
+ }
if(opts.lastRoute == undefined || opts.lastRoute == true) {
app.use(function(req, res, next){
@@ -32,7 +38,7 @@ ex.bind = function(app, opts){
app.error(function(err, req, res, next){
if(!err.name || err.name == 'Error' || !ex.hasOwnProperty(err.name)){
console.log('>>', err);
- if(req.xhr)
+ if(req.xhr || opts.plain)
return res.send({ error: 'Internal error' }, 500);
return res.render('errors/500', {
@@ -47,14 +53,17 @@ ex.bind = function(app, opts){
if(req.xhr)
return res.send({ error: err.message }, err.status);
- res.render('errors/' + err.status, {
- layout: opts.layout,
- status: err.status,
- error: err,
- showStack: app.settings.showStackError,
- title: err.message
- });
-
+ if(opts.plain){
+ res.send(err.message, err.status);
+ } else {
+ res.render('errors/' + err.status, {
+ layout: opts.layout,
+ status: err.status,
+ error: err,
+ showStack: app.settings.showStackError,
+ title: err.message
+ });
+ }
});
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Corpix <me@corpix.ru> (http://corpix.ru)",
"name": "express-errors",
"description": "Error handler",
- "version": "0.0.8-1",
+ "version": "0.0.9",
"repository": {
"type": "git",
"url": "git://github.com/corpix/express-errors.git"

0 comments on commit ce8b26a

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