Skip to content

Commit

Permalink
Fix: Authentication error handling (#1547)
Browse files Browse the repository at this point in the history
* disable linting rule when throwing authentication errors

* add missing semi-colons
  • Loading branch information
Onokaev authored Mar 10, 2022
1 parent 1b428c8 commit 0ef55d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/app/views/authentication/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
9 changes: 5 additions & 4 deletions src/modules/authentication/AuthenticationWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export class AuthenticationWrapper implements IAuthenticationWrapper {

public async logIn(sessionId = ''): Promise<AuthenticationResult> {
this.consentingToNewScopes = false;
// eslint-disable-next-line no-useless-catch
try {
return await this.getAuthResult([], sessionId);
} catch (error) {
throw new Error(`${error}`);
throw error;
}
}

Expand All @@ -65,11 +66,11 @@ export class AuthenticationWrapper implements IAuthenticationWrapper {
*/
public async consentToScopes(scopes: string[] = []): Promise<AuthenticationResult> {
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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/authentication/authentication-error-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 0ef55d6

Please sign in to comment.