Permalink
Browse files

Add support for registering an error without providing a name.

  • Loading branch information...
1 parent 8651ce9 commit 9d1c74eeadf30fc07b2abb155e0ac02d3140896b @vesln vesln committed Feb 24, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/errs.js
View
@@ -134,13 +134,17 @@ exports.handle = function (error, callback) {
//
// ### function register (type, proto)
-// #### @type {string} Type of the error to register.
+// #### @type {string} **Optional** Type of the error to register.
// #### @proto {function} Constructor function of the error to register.
//
// Registers the specified `proto` to `type` for future calls to
// `errors.create(type, opts)`.
//
exports.register = function (type, proto) {
+ if (arguments.length === 1) {
+ proto = type;
+ type = proto.name.toLowerCase();
+ }
exports.registered[type] = proto;
};
@@ -153,4 +157,4 @@ exports.register = function (type, proto) {
//
exports.unregister = function (type) {
delete exports.registered[type];
-};
+};

0 comments on commit 9d1c74e

Please sign in to comment.