Skip to content

Replace "any" types with "object" in errors and add types to OAuthError #3

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

Open
wants to merge 3 commits into
base: v5.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ __pycache__/

# files
.DS_Store

*.pyc
/aio
2 changes: 1 addition & 1 deletion lib/errors/access-denied-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/insufficient-scope-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/invalid-argument-error.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/invalid-client-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/invalid-grant-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/invalid-request-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/invalid-scope-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
4 changes: 2 additions & 2 deletions lib/errors/invalid-token-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error';
*/

export class InvalidTokenError extends OAuthError {
constructor(message?: string | Error, properties?: any) {
super(message, { code: 401, name: 'invalid_token', ...properties });
constructor(message?: string | Error, properties?: object) {
super(message, { code: 400, name: 'invalid_token', ...properties });
}
}
17 changes: 13 additions & 4 deletions lib/errors/oauth-error.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/errors/server-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OAuthError } from './oauth-error';
*/

export class ServerError extends OAuthError {
constructor(message?: string | Error, properties?: any) {
super(message, { code: 500, name: 'server_error', ...properties });
constructor(message?: string | Error, properties?: object) {
super(message, { code: 503, name: 'server_error', ...properties });
}
}
5 changes: 1 addition & 4 deletions lib/errors/unauthorized-client-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { OAuthError } from './oauth-error';
*/

export class UnauthorizedClientError extends OAuthError {
constructor(
message?: string | Error,
properties?: { code?: number; message?: string },
) {
constructor(message?: string | Error, properties?: object) {
super(message, { code: 400, name: 'unauthorized_client', ...properties });
}
}
2 changes: 1 addition & 1 deletion lib/errors/unauthorized-request-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion lib/errors/unsupported-grant-type-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/errors/unsupported-response-type-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down