Skip to content

refactor: Remove util.inherits #70 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3a7e198
refactor: Remove util.inherits #70
Dec 18, 2021
9460888
refactor: Remove util.inherits #70
Dec 18, 2021
60afc18
refactor: Remove util.inherits #70
Dec 19, 2021
c73b5b2
change Object.assign to spread operator
Dec 19, 2021
1d7b401
captureStackTrace removed from OAuthError constructor
Dec 19, 2021
186d85f
fix super constructor call OAuthError
Dec 21, 2021
ab48e15
OAuthError unit test
Dec 21, 2021
c2e6409
revert package.json
Feb 1, 2022
6536fe2
Merge branch 'development-upstream' into development
Jul 22, 2022
bb96022
Merge branch 'development' into development
jankapunkt Mar 21, 2023
aa386b8
Merge pull request #184 from node-oauth/development
jankapunkt May 30, 2023
b500792
build(deps-dev): bump sinon from 13.0.1 to 15.1.0
dependabot[bot] May 30, 2023
4bcb34a
build(deps-dev): bump chai from 4.3.4 to 4.3.7
dependabot[bot] May 30, 2023
f9e53ef
Merge pull request #185 from node-oauth/dependabot/npm_and_yarn/sinon…
jankapunkt May 31, 2023
af84281
build(deps-dev): bump mocha from 9.2.2 to 10.2.0
dependabot[bot] May 31, 2023
d0446f4
Merge pull request #186 from node-oauth/dependabot/npm_and_yarn/mocha…
jankapunkt May 31, 2023
67340df
Merge pull request #187 from node-oauth/dependabot/npm_and_yarn/chai-…
jankapunkt May 31, 2023
b08dafe
build(deps-dev): bump eslint from 8.4.1 to 8.41.0
dependabot[bot] May 31, 2023
a03defc
Merge pull request #188 from node-oauth/dependabot/npm_and_yarn/eslin…
jankapunkt Jun 5, 2023
0ea263d
build(deps-dev): bump eslint from 8.41.0 to 8.42.0
dependabot[bot] Jun 5, 2023
4494564
Merge pull request #189 from node-oauth/dependabot/npm_and_yarn/eslin…
jankapunkt Jun 5, 2023
f2f6c21
Merge branch 'master' into development
jankapunkt Jun 6, 2023
e00a630
Update authorization-code-grant-type.js
jankapunkt Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions lib/errors/access-denied-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -15,21 +14,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6749#section-4.1.2.1
*/

function AccessDeniedError(message, properties) {
properties = Object.assign({
code: 400,
name: 'access_denied'
}, properties);
class AccessDeniedError extends OAuthError {
constructor(message, properties) {
properties = {
code: 400,
name: 'access_denied',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(AccessDeniedError, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/insufficient-scope-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -15,21 +14,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6750.html#section-3.1
*/

function InsufficientScopeError(message, properties) {
properties = Object.assign({
code: 403,
name: 'insufficient_scope'
}, properties);
class InsufficientScopeError extends OAuthError {
constructor(message, properties) {
properties = {
code: 403,
name: 'insufficient_scope',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InsufficientScopeError, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/invalid-argument-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
*/

function InvalidArgumentError(message, properties) {
properties = Object.assign({
code: 500,
name: 'invalid_argument'
}, properties);
class InvalidArgumentError extends OAuthError {
constructor(message, properties) {
properties = {
code: 500,
name: 'invalid_argument',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InvalidArgumentError, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/invalid-client-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -16,21 +15,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6749#section-5.2
*/

function InvalidClientError(message, properties) {
properties = Object.assign({
code: 400,
name: 'invalid_client'
}, properties);
class InvalidClientError extends OAuthError {
constructor(message, properties) {
properties = {
code: 400,
name: 'invalid_client',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InvalidClientError, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/invalid-grant-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -17,21 +16,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6749#section-5.2
*/

function InvalidGrantError(message, properties) {
properties = Object.assign({
code: 400,
name: 'invalid_grant'
}, properties);
class InvalidGrantError extends OAuthError {
constructor(message, properties) {
properties = {
code: 400,
name: 'invalid_grant',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InvalidGrantError, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/invalid-request-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -16,21 +15,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6749#section-4.2.2.1
*/

function InvalidRequest(message, properties) {
properties = Object.assign({
code: 400,
name: 'invalid_request'
}, properties);
class InvalidRequest extends OAuthError {
constructor(message, properties) {
properties = {
code: 400,
name: 'invalid_request',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InvalidRequest, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/invalid-scope-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -15,21 +14,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6749#section-4.1.2.1
*/

function InvalidScopeError(message, properties) {
properties = Object.assign({
code: 400,
name: 'invalid_scope'
}, properties);
class InvalidScopeError extends OAuthError {
constructor(message, properties) {
properties = {
code: 400,
name: 'invalid_scope',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InvalidScopeError, OAuthError);

/**
* Export constructor.
*/
Expand Down
22 changes: 9 additions & 13 deletions lib/errors/invalid-token-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const OAuthError = require('./oauth-error');
const util = require('util');

/**
* Constructor.
Expand All @@ -15,21 +14,18 @@ const util = require('util');
* @see https://tools.ietf.org/html/rfc6750#section-3.1
*/

function InvalidTokenError(message, properties) {
properties = Object.assign({
code: 401,
name: 'invalid_token'
}, properties);
class InvalidTokenError extends OAuthError {
constructor(message, properties) {
properties = {
code: 401,
name: 'invalid_token',
...properties
};

OAuthError.call(this, message, properties);
super(message, properties);
}
}

/**
* Inherit prototype.
*/

util.inherits(InvalidTokenError, OAuthError);

/**
* Export constructor.
*/
Expand Down
48 changes: 26 additions & 22 deletions lib/errors/oauth-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,43 @@
/**
* Module dependencies.
*/
const util = require('util');
const http = require('http');
/**
* Constructor.
*/

function OAuthError(messageOrError, properties) {
let message = messageOrError instanceof Error ? messageOrError.message : messageOrError;
const error = messageOrError instanceof Error ? messageOrError : null;
if (properties == null || !Object.entries(properties).length ) {
properties = {};
}
class OAuthError extends Error {
constructor(messageOrError, properties) {
super(messageOrError, properties);

properties = Object.assign({ code: 500 }, properties);
let message = messageOrError instanceof Error ? messageOrError.message : messageOrError;
const error = messageOrError instanceof Error ? messageOrError : null;

if (error) {
properties.inner = error;
}
if (!message || message.length === 0) {
message = http.STATUS_CODES[properties.code];
}
this.code = this.status = this.statusCode = properties.code;
this.message = message;
for (const key in properties) {
if (key !== 'code') {
this[key] = properties[key];
if (properties == null || !Object.entries(properties).length) {
properties = {};
}

properties = { code: 500, ...properties };

if (error) {
properties.inner = error;
}

if (!message || message.length === 0) {
message = http.STATUS_CODES[properties.code];
}

this.code = this.status = this.statusCode = properties.code;
this.message = message;

for (const key in properties) {
if (key !== 'code') {
this[key] = properties[key];
}
}
}
Error.captureStackTrace(this, OAuthError);
}

util.inherits(OAuthError, Error);

/**
* Export constructor.
*/
Expand Down
Loading