From caa86886cc2153eb8f873eac412f7bf310273e24 Mon Sep 17 00:00:00 2001 From: ankit Date: Wed, 24 Apr 2019 18:11:34 +0700 Subject: [PATCH 1/2] updated-gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8cac61aeb..5735e5988 100755 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ npm-debug.log .DS_Store # conf +/aio \ No newline at end of file From 040e05b89ececca00d12bd671f8894ba01627a0e Mon Sep 17 00:00:00 2001 From: Gasim Gasimzada Date: Wed, 11 Sep 2019 16:17:27 +0400 Subject: [PATCH 2/2] Replace "any" with "object" in errors and create interface for OAuthError class props --- lib/errors/access-denied-error.ts | 2 +- lib/errors/insufficient-scope-error.ts | 2 +- lib/errors/invalid-argument-error.ts | 2 +- lib/errors/invalid-client-error.ts | 2 +- lib/errors/invalid-grant-error.ts | 2 +- lib/errors/invalid-request-error.ts | 2 +- lib/errors/invalid-scope-error.ts | 2 +- lib/errors/invalid-token-error.ts | 2 +- lib/errors/oauth-error.ts | 17 +++++++++++++---- lib/errors/server-error.ts | 2 +- lib/errors/unauthorized-client-error.ts | 2 +- lib/errors/unauthorized-request-error.ts | 2 +- lib/errors/unsupported-grant-type-error.ts | 2 +- lib/errors/unsupported-response-type-error.ts | 2 +- 14 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/errors/access-denied-error.ts b/lib/errors/access-denied-error.ts index 681ca61ab..f067cc9d5 100755 --- a/lib/errors/access-denied-error.ts +++ b/lib/errors/access-denied-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class AccessDeniedError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'access_denied', ...properties }); } } diff --git a/lib/errors/insufficient-scope-error.ts b/lib/errors/insufficient-scope-error.ts index f50b4a9e5..8f7e89f41 100755 --- a/lib/errors/insufficient-scope-error.ts +++ b/lib/errors/insufficient-scope-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class InsufficientScopeError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 403, name: 'insufficient_scope', ...properties }); } } diff --git a/lib/errors/invalid-argument-error.ts b/lib/errors/invalid-argument-error.ts index b4c5adbd2..6370d40e4 100755 --- a/lib/errors/invalid-argument-error.ts +++ b/lib/errors/invalid-argument-error.ts @@ -1,7 +1,7 @@ import { OAuthError } from './oauth-error'; export class InvalidArgumentError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 500, name: 'invalid_argument', ...properties }); } } diff --git a/lib/errors/invalid-client-error.ts b/lib/errors/invalid-client-error.ts index 8c296a2d0..93f621a9c 100755 --- a/lib/errors/invalid-client-error.ts +++ b/lib/errors/invalid-client-error.ts @@ -10,7 +10,7 @@ import { OAuthError } from './oauth-error'; */ export class InvalidClientError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'invalid_client', ...properties }); } } diff --git a/lib/errors/invalid-grant-error.ts b/lib/errors/invalid-grant-error.ts index 8c37a3c9f..71dfdaf9a 100755 --- a/lib/errors/invalid-grant-error.ts +++ b/lib/errors/invalid-grant-error.ts @@ -11,7 +11,7 @@ import { OAuthError } from './oauth-error'; */ export class InvalidGrantError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'invalid_grant', ...properties }); } } diff --git a/lib/errors/invalid-request-error.ts b/lib/errors/invalid-request-error.ts index 6fe0a253b..6afcecaaf 100755 --- a/lib/errors/invalid-request-error.ts +++ b/lib/errors/invalid-request-error.ts @@ -10,7 +10,7 @@ import { OAuthError } from './oauth-error'; */ export class InvalidRequestError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'invalid_request', ...properties }); } } diff --git a/lib/errors/invalid-scope-error.ts b/lib/errors/invalid-scope-error.ts index 6f3977fb5..474914c3e 100755 --- a/lib/errors/invalid-scope-error.ts +++ b/lib/errors/invalid-scope-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class InvalidScopeError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'invalid_scope', ...properties }); } } diff --git a/lib/errors/invalid-token-error.ts b/lib/errors/invalid-token-error.ts index 655e347ce..f4177085b 100755 --- a/lib/errors/invalid-token-error.ts +++ b/lib/errors/invalid-token-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class InvalidTokenError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'invalid_token', ...properties }); } } diff --git a/lib/errors/oauth-error.ts b/lib/errors/oauth-error.ts index 30151aa08..b918e883b 100755 --- a/lib/errors/oauth-error.ts +++ b/lib/errors/oauth-error.ts @@ -1,11 +1,20 @@ import { defaults, isEmpty } from 'lodash'; import * as statuses from 'statuses'; +interface OAuthErrorProperties { + code: number; + name: string; + [propName: string]: any; +} + export class OAuthError extends Error { - code: any; - status: any; - statusCode: any; - constructor(messageOrError: string | Error, properties?: any) { + code: number; + status: number; + statusCode: number; + constructor( + messageOrError: string | Error, + properties?: OAuthErrorProperties, + ) { super(); let message = messageOrError instanceof Error ? messageOrError.message : messageOrError; diff --git a/lib/errors/server-error.ts b/lib/errors/server-error.ts index 3d3a478f4..873fd436d 100755 --- a/lib/errors/server-error.ts +++ b/lib/errors/server-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class ServerError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 503, name: 'server_error', ...properties }); } } diff --git a/lib/errors/unauthorized-client-error.ts b/lib/errors/unauthorized-client-error.ts index e0e5f6a18..7e94c1f7e 100755 --- a/lib/errors/unauthorized-client-error.ts +++ b/lib/errors/unauthorized-client-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class UnauthorizedClientError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'unauthorized_client', ...properties }); } } diff --git a/lib/errors/unauthorized-request-error.ts b/lib/errors/unauthorized-request-error.ts index ba98235da..1458fb39c 100755 --- a/lib/errors/unauthorized-request-error.ts +++ b/lib/errors/unauthorized-request-error.ts @@ -12,7 +12,7 @@ import { OAuthError } from './oauth-error'; */ export class UnauthorizedRequestError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 401, name: 'unauthorized_request', ...properties }); } } diff --git a/lib/errors/unsupported-grant-type-error.ts b/lib/errors/unsupported-grant-type-error.ts index 7a249d343..81de076e0 100755 --- a/lib/errors/unsupported-grant-type-error.ts +++ b/lib/errors/unsupported-grant-type-error.ts @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error'; */ export class UnsupportedGrantTypeError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'unsupported_grant_type', diff --git a/lib/errors/unsupported-response-type-error.ts b/lib/errors/unsupported-response-type-error.ts index 14c3f9e83..37f6464ad 100755 --- a/lib/errors/unsupported-response-type-error.ts +++ b/lib/errors/unsupported-response-type-error.ts @@ -10,7 +10,7 @@ import { OAuthError } from './oauth-error'; */ export class UnsupportedResponseTypeError extends OAuthError { - constructor(message?: string | Error, properties?: any) { + constructor(message?: string | Error, properties?: object) { super(message, { code: 400, name: 'unsupported_response_type',