From f15ad0848ade004198e8b280b8079176ee1567fa Mon Sep 17 00:00:00 2001 From: Daniel Fischer Date: Sat, 21 Jul 2018 03:11:58 +0200 Subject: [PATCH] [oauth2-server] Add error classes (#27201) * [oauth2-server] Add error classes * [oauth2-server] Add code and name to OAuthError - they seem to be set by all subclasses * [oauth2-server] Add message to OAuthError * [oauth2-server] validateScope should actually return a string, not an array * [oauth2-server] correct properties of OAuthError --- types/oauth2-server/index.d.ts | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/types/oauth2-server/index.d.ts b/types/oauth2-server/index.d.ts index 6729a05e7e..6c20aab221 100644 --- a/types/oauth2-server/index.d.ts +++ b/types/oauth2-server/index.d.ts @@ -1,7 +1,8 @@ // Type definitions for Node OAuth2 Server 3.0 // Project: https://github.com/oauthjs/node-oauth2-server // Definitions by: Robbie Van Gorkom , -// Charles Irick +// Charles Irick , +// Daniel Fischer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -263,7 +264,7 @@ declare namespace OAuth2Server { * Invoked to check if the requested scope is valid for a particular client/user combination. * */ - validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; + validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; } interface PasswordModel extends BaseModel, RequestAuthenticationModel { @@ -283,7 +284,7 @@ declare namespace OAuth2Server { * Invoked to check if the requested scope is valid for a particular client/user combination. * */ - validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; + validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; } interface RefreshTokenModel extends BaseModel, RequestAuthenticationModel { @@ -317,7 +318,7 @@ declare namespace OAuth2Server { * Invoked to check if the requested scope is valid for a particular client/user combination. * */ - validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; + validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; } interface ExtensionModel extends BaseModel, RequestAuthenticationModel {} @@ -380,6 +381,39 @@ declare namespace OAuth2Server { user: User; [key: string]: any; } + + class OAuthError extends Error { + constructor(messageOrError: string | Error, properties?: object); + + /** + * The HTTP error code. + */ + code: number; + + /** + * The OAuth error code. + */ + name: string; + + /** + * A human-readable error message. + */ + message: string; + } + + class AccessDeniedError extends OAuthError {} + class InsufficientScopeError extends OAuthError {} + class InvalidArgumentError extends OAuthError {} + class InvalidClientError extends OAuthError {} + class InvalidGrantError extends OAuthError {} + class InvalidRequestError extends OAuthError {} + class InvalidScopeError extends OAuthError {} + class InvalidTokenError extends OAuthError {} + class ServerError extends OAuthError {} + class UnauthorizedClientError extends OAuthError {} + class UnauthorizedRequestError extends OAuthError {} + class UnsupportedGrantTypeError extends OAuthError {} + class UnsupportedResponseTypeError extends OAuthError {} } export = OAuth2Server;