Skip to content

Commit 9fd04f6

Browse files
authored
refactor(deps): remove util.inherits #70
Merge pull request #109 from dsschiramm/development Thanks to @dsschiramm
2 parents 0e3cfe0 + e00a630 commit 9fd04f6

20 files changed

+650
-683
lines changed

lib/errors/access-denied-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

18-
function AccessDeniedError(message, properties) {
19-
properties = Object.assign({
20-
code: 400,
21-
name: 'access_denied'
22-
}, properties);
17+
class AccessDeniedError extends OAuthError {
18+
constructor(message, properties) {
19+
properties = {
20+
code: 400,
21+
name: 'access_denied',
22+
...properties
23+
};
2324

24-
OAuthError.call(this, message, properties);
25+
super(message, properties);
26+
}
2527
}
2628

27-
/**
28-
* Inherit prototype.
29-
*/
30-
31-
util.inherits(AccessDeniedError, OAuthError);
32-
3329
/**
3430
* Export constructor.
3531
*/

lib/errors/insufficient-scope-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

18-
function InsufficientScopeError(message, properties) {
19-
properties = Object.assign({
20-
code: 403,
21-
name: 'insufficient_scope'
22-
}, properties);
17+
class InsufficientScopeError extends OAuthError {
18+
constructor(message, properties) {
19+
properties = {
20+
code: 403,
21+
name: 'insufficient_scope',
22+
...properties
23+
};
2324

24-
OAuthError.call(this, message, properties);
25+
super(message, properties);
26+
}
2527
}
2628

27-
/**
28-
* Inherit prototype.
29-
*/
30-
31-
util.inherits(InsufficientScopeError, OAuthError);
32-
3329
/**
3430
* Export constructor.
3531
*/

lib/errors/invalid-argument-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@
55
*/
66

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

109
/**
1110
* Constructor.
1211
*/
1312

14-
function InvalidArgumentError(message, properties) {
15-
properties = Object.assign({
16-
code: 500,
17-
name: 'invalid_argument'
18-
}, properties);
13+
class InvalidArgumentError extends OAuthError {
14+
constructor(message, properties) {
15+
properties = {
16+
code: 500,
17+
name: 'invalid_argument',
18+
...properties
19+
};
1920

20-
OAuthError.call(this, message, properties);
21+
super(message, properties);
22+
}
2123
}
2224

23-
/**
24-
* Inherit prototype.
25-
*/
26-
27-
util.inherits(InvalidArgumentError, OAuthError);
28-
2925
/**
3026
* Export constructor.
3127
*/

lib/errors/invalid-client-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

19-
function InvalidClientError(message, properties) {
20-
properties = Object.assign({
21-
code: 400,
22-
name: 'invalid_client'
23-
}, properties);
18+
class InvalidClientError extends OAuthError {
19+
constructor(message, properties) {
20+
properties = {
21+
code: 400,
22+
name: 'invalid_client',
23+
...properties
24+
};
2425

25-
OAuthError.call(this, message, properties);
26+
super(message, properties);
27+
}
2628
}
2729

28-
/**
29-
* Inherit prototype.
30-
*/
31-
32-
util.inherits(InvalidClientError, OAuthError);
33-
3430
/**
3531
* Export constructor.
3632
*/

lib/errors/invalid-grant-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

20-
function InvalidGrantError(message, properties) {
21-
properties = Object.assign({
22-
code: 400,
23-
name: 'invalid_grant'
24-
}, properties);
19+
class InvalidGrantError extends OAuthError {
20+
constructor(message, properties) {
21+
properties = {
22+
code: 400,
23+
name: 'invalid_grant',
24+
...properties
25+
};
2526

26-
OAuthError.call(this, message, properties);
27+
super(message, properties);
28+
}
2729
}
2830

29-
/**
30-
* Inherit prototype.
31-
*/
32-
33-
util.inherits(InvalidGrantError, OAuthError);
34-
3531
/**
3632
* Export constructor.
3733
*/

lib/errors/invalid-request-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

19-
function InvalidRequest(message, properties) {
20-
properties = Object.assign({
21-
code: 400,
22-
name: 'invalid_request'
23-
}, properties);
18+
class InvalidRequest extends OAuthError {
19+
constructor(message, properties) {
20+
properties = {
21+
code: 400,
22+
name: 'invalid_request',
23+
...properties
24+
};
2425

25-
OAuthError.call(this, message, properties);
26+
super(message, properties);
27+
}
2628
}
2729

28-
/**
29-
* Inherit prototype.
30-
*/
31-
32-
util.inherits(InvalidRequest, OAuthError);
33-
3430
/**
3531
* Export constructor.
3632
*/

lib/errors/invalid-scope-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

18-
function InvalidScopeError(message, properties) {
19-
properties = Object.assign({
20-
code: 400,
21-
name: 'invalid_scope'
22-
}, properties);
17+
class InvalidScopeError extends OAuthError {
18+
constructor(message, properties) {
19+
properties = {
20+
code: 400,
21+
name: 'invalid_scope',
22+
...properties
23+
};
2324

24-
OAuthError.call(this, message, properties);
25+
super(message, properties);
26+
}
2527
}
2628

27-
/**
28-
* Inherit prototype.
29-
*/
30-
31-
util.inherits(InvalidScopeError, OAuthError);
32-
3329
/**
3430
* Export constructor.
3531
*/

lib/errors/invalid-token-error.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

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

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

18-
function InvalidTokenError(message, properties) {
19-
properties = Object.assign({
20-
code: 401,
21-
name: 'invalid_token'
22-
}, properties);
17+
class InvalidTokenError extends OAuthError {
18+
constructor(message, properties) {
19+
properties = {
20+
code: 401,
21+
name: 'invalid_token',
22+
...properties
23+
};
2324

24-
OAuthError.call(this, message, properties);
25+
super(message, properties);
26+
}
2527
}
2628

27-
/**
28-
* Inherit prototype.
29-
*/
30-
31-
util.inherits(InvalidTokenError, OAuthError);
32-
3329
/**
3430
* Export constructor.
3531
*/

lib/errors/oauth-error.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,43 @@
33
/**
44
* Module dependencies.
55
*/
6-
const util = require('util');
76
const http = require('http');
87
/**
98
* Constructor.
109
*/
1110

12-
function OAuthError(messageOrError, properties) {
13-
let message = messageOrError instanceof Error ? messageOrError.message : messageOrError;
14-
const error = messageOrError instanceof Error ? messageOrError : null;
15-
if (properties == null || !Object.entries(properties).length ) {
16-
properties = {};
17-
}
11+
class OAuthError extends Error {
12+
constructor(messageOrError, properties) {
13+
super(messageOrError, properties);
1814

19-
properties = Object.assign({ code: 500 }, properties);
15+
let message = messageOrError instanceof Error ? messageOrError.message : messageOrError;
16+
const error = messageOrError instanceof Error ? messageOrError : null;
2017

21-
if (error) {
22-
properties.inner = error;
23-
}
24-
if (!message || message.length === 0) {
25-
message = http.STATUS_CODES[properties.code];
26-
}
27-
this.code = this.status = this.statusCode = properties.code;
28-
this.message = message;
29-
for (const key in properties) {
30-
if (key !== 'code') {
31-
this[key] = properties[key];
18+
if (properties == null || !Object.entries(properties).length) {
19+
properties = {};
20+
}
21+
22+
properties = { code: 500, ...properties };
23+
24+
if (error) {
25+
properties.inner = error;
26+
}
27+
28+
if (!message || message.length === 0) {
29+
message = http.STATUS_CODES[properties.code];
30+
}
31+
32+
this.code = this.status = this.statusCode = properties.code;
33+
this.message = message;
34+
35+
for (const key in properties) {
36+
if (key !== 'code') {
37+
this[key] = properties[key];
38+
}
3239
}
3340
}
34-
Error.captureStackTrace(this, OAuthError);
3541
}
3642

37-
util.inherits(OAuthError, Error);
38-
3943
/**
4044
* Export constructor.
4145
*/

0 commit comments

Comments
 (0)