From 0ef55d6f89ac82a5e34132bcbcbfefadf83cfbba Mon Sep 17 00:00:00 2001 From: EvansA Date: Thu, 10 Mar 2022 16:20:19 +0300 Subject: [PATCH] Fix: Authentication error handling (#1547) * disable linting rule when throwing authentication errors * add missing semi-colons --- src/app/views/authentication/Authentication.tsx | 7 +------ src/modules/authentication/AuthenticationWrapper.ts | 9 +++++---- src/modules/authentication/authentication-error-hints.ts | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/app/views/authentication/Authentication.tsx b/src/app/views/authentication/Authentication.tsx index 43b357c95..fd5137a4e 100644 --- a/src/app/views/authentication/Authentication.tsx +++ b/src/app/views/authentication/Authentication.tsx @@ -68,12 +68,7 @@ const Authentication = (props: any) => { }; const removeUnderScore = (statusString: string): string => { - if (statusString === '') { - return statusString; - } - else { - return statusString.replace(/_/g, ' '); - } + return statusString ? statusString.replace(/_/g, ' ') : statusString; } const showProgressSpinner = (): React.ReactNode => { diff --git a/src/modules/authentication/AuthenticationWrapper.ts b/src/modules/authentication/AuthenticationWrapper.ts index 5f04ca76d..9e5b98e6d 100644 --- a/src/modules/authentication/AuthenticationWrapper.ts +++ b/src/modules/authentication/AuthenticationWrapper.ts @@ -41,10 +41,11 @@ export class AuthenticationWrapper implements IAuthenticationWrapper { public async logIn(sessionId = ''): Promise { this.consentingToNewScopes = false; + // eslint-disable-next-line no-useless-catch try { return await this.getAuthResult([], sessionId); } catch (error) { - throw new Error(`${error}`); + throw error; } } @@ -65,11 +66,11 @@ export class AuthenticationWrapper implements IAuthenticationWrapper { */ public async consentToScopes(scopes: string[] = []): Promise { this.consentingToNewScopes = true; + // eslint-disable-next-line no-useless-catch try { - const authResult = await this.loginWithInteraction(scopes); - return authResult; + return await this.loginWithInteraction(scopes); } catch (error) { - throw new Error(`${error}`); + throw error; } } diff --git a/src/modules/authentication/authentication-error-hints.ts b/src/modules/authentication/authentication-error-hints.ts index 30b5358d1..f9808bddc 100644 --- a/src/modules/authentication/authentication-error-hints.ts +++ b/src/modules/authentication/authentication-error-hints.ts @@ -15,7 +15,7 @@ export function getSignInAuthErrorHint(error: string): string { } export function signInAuthError(error: string): boolean { - return authErrorList.includes(error.trim()); + return error ? authErrorList.includes(error) : false; } export function getConsentAuthErrorHint(error: string): string { @@ -25,7 +25,7 @@ export function getConsentAuthErrorHint(error: string): string { } export function scopeAuthError(error: string): boolean { - return scopeErrorList.includes(error); + return error ? scopeErrorList.includes(error) : false; } function getHint(error: string): string {