diff --git a/src/app/_interceptors/error.interceptor.ts b/src/app/_interceptors/error.interceptor.ts index 2f53f1b..4e2deea 100644 --- a/src/app/_interceptors/error.interceptor.ts +++ b/src/app/_interceptors/error.interceptor.ts @@ -14,7 +14,7 @@ import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; // Application imports -import { LoggingService } from '@app/_services'; +import { ErrorDialogService, LoggingService } from '@app/_services'; /** Intercepts and handles errors from outgoing HTTP request. */ @Injectable() @@ -22,10 +22,15 @@ export class ErrorInterceptor implements HttpInterceptor { /** * Initialization of the error interceptor. * + * @param errorDialogService - A service that provides a dialog box for displaying errors to the user. * @param loggingService - A service that provides logging capabilities. * @param router - A service that provides navigation among views and URL manipulation capabilities. */ - constructor(private loggingService: LoggingService, private router: Router) {} + constructor( + private errorDialogService: ErrorDialogService, + private loggingService: LoggingService, + private router: Router + ) {} /** * Intercepts HTTP requests. @@ -54,9 +59,10 @@ export class ErrorInterceptor implements HttpInterceptor { this.router.navigateByUrl('/auth').then(); break; case 403: // forbidden - this.errorDialogService.openDialog( - { message: 'Access to resource is not allowed (Error 403)'}) - //alert('Access to resource is not allowed!'); + this.errorDialogService.openDialog({ + message: 'Access to resource is not allowed (Error 403)', + }); + // alert('Access to resource is not allowed!'); break; } // Return an observable with a user-facing error message. diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index 63982fd..9342b11 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -46,7 +46,7 @@ export class AuthService { } getWithToken(): Promise { - const sessionToken = this.getSessionToken() + const sessionToken = this.getSessionToken(); const headers = { Authorization: 'Bearer ' + sessionToken, 'Content-Type': 'application/json;charset=utf-8', @@ -92,33 +92,32 @@ export class AuthService { async login(): Promise { if (this.getSessionToken()) { sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN')); - } + } const o = await this.getChallenge(); const r = await signChallenge( - o.challenge, - o.realm, - environment.cicMetaUrl, - this.mutableKeyStore + o.challenge, + o.realm, + environment.cicMetaUrl, + this.mutableKeyStore ); - const tokenResponse = await this.sendSignedChallenge(r) - .then((response) => { - const token = response.headers.get('Token'); - if (token) { - return token; - } - if (response.status === 401) { - throw new HttpError('You are not authorized to use this system', response.status); - } - if (!response.ok) { - throw new HttpError('Unknown error from authentication server', response.status); - } + const tokenResponse = await this.sendSignedChallenge(r).then((response) => { + const token = response.headers.get('Token'); + if (token) { + return token; + } + if (response.status === 401) { + throw new HttpError('You are not authorized to use this system', response.status); + } + if (!response.ok) { + throw new HttpError('Unknown error from authentication server', response.status); + } }); if (tokenResponse) { this.setSessionToken(tokenResponse); - //this.setState('Click button to log in'); + // this.setState('Click button to log in'); return true; } return false; diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index a51d47e..cf72b96 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -57,7 +57,7 @@ export class AuthComponent implements OnInit { } } catch (HttpError) { this.errorDialogService.openDialog({ - message: "Failed to login please try again.", + message: 'Failed to login please try again.', }); } }