Permalink
Browse files

Getters

  • Loading branch information...
1 parent 51787cf commit 2d2630c64605c03eb0c8dc0c99c1b6bbec8ac483 @corpix committed Dec 27, 2011
Showing with 19 additions and 4 deletions.
  1. +18 −3 index.js
  2. +1 −1 package.json
View
21 index.js
@@ -9,9 +9,24 @@ function NotFound(){
Error.captureStackTrace(this, arguments.callee);
}
-NotFound.prototype.__proto__ = Error.prototype;
+////
+// Error types comming here ->
+//
-ex.NotFound = NotFound;
+ex._NotFound = NotFound;
+
+for(var i in ex){
+ ex[i].prototype.__proto__ = Error.prototype;
+ (function(name, cl){
+ ex.__defineGetter__(name, function(){
+ return new cl()
+ });
+ })(i.slice(1), ex[i]);
+}
+
+////
+// <-
+//
ex.bind = function(app, opts){
@@ -20,7 +35,7 @@ ex.bind = function(app, opts){
});
app.error(function(err, req, res, next){
- if(!err.name || err.name == 'Error' || !ex[err.name]){
+ if(!err.name || err.name == 'Error' || !ex['_' + err.name]){
console.log(err.stack);
if(req.xhr)
return res.send({ error: 'Internal error' }, 500);
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.2",
+ "version": "0.0.3",
"repository": {
"type": "git",
"url": "git://github.com/corpix/express-errors.git"

0 comments on commit 2d2630c

Please sign in to comment.