Skip to content

Commit

Permalink
Only AuthorizationError and TokenError are OAuth 2-specific errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 18, 2015
1 parent 84b4998 commit 2bcb1ca
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 59 deletions.
11 changes: 3 additions & 8 deletions lib/errors/badrequesterror.js
@@ -1,25 +1,20 @@
/**
* 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;
this.status = 400;
}

/**
* Inherit from `Oauth2Error`.
* Inherit from `Error`.
*/
BadRequestError.prototype.__proto__ = Oauth2Error.prototype;
BadRequestError.prototype.__proto__ = Error.prototype;


/**
Expand Down
11 changes: 3 additions & 8 deletions lib/errors/forbiddenerror.js
@@ -1,25 +1,20 @@
/**
* 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;
this.status = 403;
}

/**
* Inherit from `Oauth2Error`.
* Inherit from `Error`.
*/
ForbiddenError.prototype.__proto__ = Oauth2Error.prototype;
ForbiddenError.prototype.__proto__ = Error.prototype;


/**
Expand Down
8 changes: 7 additions & 1 deletion 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() {
Expand All @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions test/errors/badrequesterror.test.js
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions test/errors/forbiddenerror.test.js
Expand Up @@ -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() {
Expand Down
41 changes: 0 additions & 41 deletions test/errors/oauth2error.test.js

This file was deleted.

8 changes: 7 additions & 1 deletion 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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 2bcb1ca

Please sign in to comment.