Browse files

Add InternalOpenIDError.

  • Loading branch information...
1 parent 6f65323 commit a6d8023b81dea3c21c3fe8fad32bc3238ae46e25 @jaredhanson committed Apr 10, 2012
View
2 Makefile
@@ -1,6 +1,6 @@
NODE = node
TEST = ./node_modules/.bin/vows
-TESTS ?= test/*-test.js
+TESTS ?= test/*-test.js test/**/*-test.js
test:
@NODE_ENV=test NODE_PATH=lib $(TEST) $(TEST_FLAGS) $(TESTS)
View
46 lib/passport-openid/errors/internalopeniderror.js
@@ -0,0 +1,46 @@
+/**
+ * `InternalOpenIDError` error.
+ *
+ * InternalOpenIDError wraps errors generated by node-openid. By wrapping these
+ * objects, error messages can be formatted in a manner that aids in debugging
+ * OpenID issues.
+ *
+ * @api public
+ */
+function InternalOpenIDError(message, err) {
+ Error.call(this);
+ Error.captureStackTrace(this, arguments.callee);
+ this.name = 'InternalOpenIDError';
+ this.message = message;
+ this.openidError = err;
+};
+
+/**
+ * Inherit from `Error`.
+ */
+InternalOpenIDError.prototype.__proto__ = Error.prototype;
+
+/**
+ * Returns a string representing the error.
+ *
+ * @return {String}
+ * @api public
+ */
+InternalOpenIDError.prototype.toString = function() {
+ var m = this.message;
+ if (this.openidError) {
+ if (this.openidError instanceof Error) {
+ m += ' (' + this.openidError + ')';
+ }
+ else if (this.openidError.message) {
+ m += ' (message: ' + this.openidError.message + ')';
+ }
+ }
+ return m;
+}
+
+
+/**
+ * Expose `InternalOpenIDError`.
+ */
+module.exports = InternalOpenIDError;
View
4 lib/passport-openid/index.js
@@ -2,7 +2,8 @@
* Module dependencies.
*/
var Strategy = require('./strategy')
- , BadRequestError = require('./errors/badrequesterror');
+ , BadRequestError = require('./errors/badrequesterror')
+ , InternalOpenIDError = require('./errors/internalopeniderror');
/**
@@ -16,3 +17,4 @@ require('pkginfo')(module, 'version');
exports.Strategy = Strategy;
exports.BadRequestError = BadRequestError;
+exports.InternalOpenIDError = InternalOpenIDError;
View
2 package.json
@@ -20,7 +20,7 @@
"vows": "0.6.x"
},
"scripts": {
- "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
+ "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js test/**/*-test.js"
},
"engines": { "node": ">= 0.4.0" },
"licenses": [ {
View
39 test/errors/internalopeniderror-test.js
@@ -0,0 +1,39 @@
+var vows = require('vows');
+var assert = require('assert');
+var util = require('util');
+var InternalOpenIDError = require('passport-openid/errors/internalopeniderror');
+
+
+vows.describe('InternalOpenIDError').addBatch({
+
+ 'when constructed with only a message': {
+ topic: function() {
+ return new InternalOpenIDError('oops');
+ },
+
+ 'should format message properly': function (err) {
+ assert.equal(err.toString(), 'oops');
+ },
+ },
+
+ 'when constructed with a message and error': {
+ topic: function() {
+ return new InternalOpenIDError('oops', new Error('something is wrong'));
+ },
+
+ 'should format message properly': function (err) {
+ assert.equal(err.toString(), 'oops (Error: something is wrong)');
+ },
+ },
+
+ 'when constructed with a message and object with message': {
+ topic: function() {
+ return new InternalOpenIDError('oops', { message: 'invalid OpenID provider' });
+ },
+
+ 'should format message properly': function (err) {
+ assert.equal(err.toString(), 'oops (message: invalid OpenID provider)');
+ },
+ },
+
+}).export(module);
View
1 test/index-test.js
@@ -13,6 +13,7 @@ vows.describe('passport-openid').addBatch({
'should export BadRequestError': function (x) {
assert.isFunction(openid.BadRequestError);
+ assert.isFunction(openid.InternalOpenIDError);
},
},

0 comments on commit a6d8023

Please sign in to comment.