From 2bcb1ca68b18b72c983e47c7b207f460e677b482 Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Wed, 18 Feb 2015 10:25:46 -0800 Subject: [PATCH] Only AuthorizationError and TokenError are OAuth 2-specific errors. --- lib/errors/badrequesterror.js | 11 ++----- lib/errors/forbiddenerror.js | 11 ++----- test/errors/authorizationerror.test.js | 8 ++++- test/errors/badrequesterror.test.js | 4 +++ test/errors/forbiddenerror.test.js | 4 +++ test/errors/oauth2error.test.js | 41 -------------------------- test/errors/tokenerror.test.js | 8 ++++- 7 files changed, 28 insertions(+), 59 deletions(-) delete mode 100644 test/errors/oauth2error.test.js diff --git a/lib/errors/badrequesterror.js b/lib/errors/badrequesterror.js index e4132a7f..c581748f 100644 --- a/lib/errors/badrequesterror.js +++ b/lib/errors/badrequesterror.js @@ -1,15 +1,10 @@ -/** - * Module dependencies. - */ -var Oauth2Error = require('./oauth2error'); - /** * `BadRequestError` error. * * @api public */ function BadRequestError(message) { - Oauth2Error.call(this); + Error.call(this); Error.captureStackTrace(this, arguments.callee); this.name = 'BadRequestError'; this.message = message; @@ -17,9 +12,9 @@ function BadRequestError(message) { } /** - * Inherit from `Oauth2Error`. + * Inherit from `Error`. */ -BadRequestError.prototype.__proto__ = Oauth2Error.prototype; +BadRequestError.prototype.__proto__ = Error.prototype; /** diff --git a/lib/errors/forbiddenerror.js b/lib/errors/forbiddenerror.js index d488936d..fd395708 100644 --- a/lib/errors/forbiddenerror.js +++ b/lib/errors/forbiddenerror.js @@ -1,15 +1,10 @@ -/** - * Module dependencies. - */ -var Oauth2Error = require('./oauth2error'); - /** * `ForbiddenError` error. * * @api public */ function ForbiddenError(message) { - Oauth2Error.call(this); + Error.call(this); Error.captureStackTrace(this, arguments.callee); this.name = 'ForbiddenError'; this.message = message; @@ -17,9 +12,9 @@ function ForbiddenError(message) { } /** - * Inherit from `Oauth2Error`. + * Inherit from `Error`. */ -ForbiddenError.prototype.__proto__ = Oauth2Error.prototype; +ForbiddenError.prototype.__proto__ = Error.prototype; /** diff --git a/test/errors/authorizationerror.test.js b/test/errors/authorizationerror.test.js index 8f8408da..15db249c 100644 --- a/test/errors/authorizationerror.test.js +++ b/test/errors/authorizationerror.test.js @@ -1,4 +1,5 @@ -var AuthorizationError = require('../../lib/errors/authorizationerror'); +var OAuth2Error = require('../../lib/errors/oauth2error') + , AuthorizationError = require('../../lib/errors/authorizationerror'); describe('AuthorizationError', function() { @@ -17,6 +18,11 @@ describe('AuthorizationError', function() { //expect(err.toString()).to.equal('AuthorizationError'); expect(err.toString().indexOf('AuthorizationError')).to.equal(0); }); + + it('should inherits from OAuth2Error and Error', function() { + expect(err).to.be.instanceof(OAuth2Error); + expect(err).to.be.instanceof(Error); + }); }); describe('constructed with a message', function() { diff --git a/test/errors/badrequesterror.test.js b/test/errors/badrequesterror.test.js index 126e1020..59cf408c 100644 --- a/test/errors/badrequesterror.test.js +++ b/test/errors/badrequesterror.test.js @@ -18,6 +18,10 @@ describe('BadRequestError', function() { it('should have status', function() { expect(err.status).to.equal(400); }); + + it('should inherits from Error', function() { + expect(err).to.be.instanceof(Error); + }); }); describe('constructed with a message', function() { diff --git a/test/errors/forbiddenerror.test.js b/test/errors/forbiddenerror.test.js index 88681684..cea0ced9 100644 --- a/test/errors/forbiddenerror.test.js +++ b/test/errors/forbiddenerror.test.js @@ -18,6 +18,10 @@ describe('ForbiddenError', function() { it('should have status', function() { expect(err.status).to.equal(403); }); + + it('should inherits from Error', function() { + expect(err).to.be.instanceof(Error); + }); }); describe('constructed with a message', function() { diff --git a/test/errors/oauth2error.test.js b/test/errors/oauth2error.test.js deleted file mode 100644 index 52f2afd9..00000000 --- a/test/errors/oauth2error.test.js +++ /dev/null @@ -1,41 +0,0 @@ -var Oauth2Error = require('../../lib/errors/oauth2error') - , AuthorizationError = require('../../lib/errors/authorizationerror') - , BadRequestError = require('../../lib/errors/badrequesterror') - , ForbiddenError = require('../../lib/errors/forbiddenerror') - , TokenError = require('../../lib/errors/tokenerror'); - - -describe('Oauth2Error', function() { - describe('AuthorizationError', function () { - var err = new AuthorizationError(); - it('should inherits from Oauth2Error and Error', function() { - expect(err).to.be.instanceof(Oauth2Error); - expect(err).to.be.instanceof(Error); - }); - }); - - describe('BadRequestError', function () { - var err = new BadRequestError(); - it('should inherits from Oauth2Error and Error', function() { - expect(err).to.be.instanceof(Oauth2Error); - expect(err).to.be.instanceof(Error); - }); - }); - - describe('ForbiddenError', function () { - var err = new ForbiddenError(); - it('should inherits from Oauth2Error and Error', function() { - expect(err).to.be.instanceof(Oauth2Error); - expect(err).to.be.instanceof(Error); - }); - }); - - describe('TokenError', function () { - var err = new TokenError(); - it('should inherits from Oauth2Error and Error', function() { - expect(err).to.be.instanceof(Oauth2Error); - expect(err).to.be.instanceof(Error); - }); - }); - -}); diff --git a/test/errors/tokenerror.test.js b/test/errors/tokenerror.test.js index b16a3f71..934abc35 100644 --- a/test/errors/tokenerror.test.js +++ b/test/errors/tokenerror.test.js @@ -1,4 +1,5 @@ -var TokenError = require('../../lib/errors/tokenerror'); +var OAuth2Error = require('../../lib/errors/oauth2error') + , TokenError = require('../../lib/errors/tokenerror'); describe('TokenError', function() { @@ -17,6 +18,11 @@ describe('TokenError', function() { //expect(err.toString()).to.equal('AuthorizationError'); expect(err.toString().indexOf('TokenError')).to.equal(0); }); + + it('should inherits from OAuth2Error and Error', function() { + expect(err).to.be.instanceof(OAuth2Error); + expect(err).to.be.instanceof(Error); + }); }); describe('constructed with a message', function() {