diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index 6cdac36..484bc9c 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -45,10 +45,13 @@ export class AuthService { }; fetch(environment.cicMetaUrl, options).then(response => { if (response.status === 401) { - return Promise.reject({ statusText: response.statusText }); + return Promise.reject({ + status: response.status, + statusText: response.statusText + }); } return; - }).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error})); + }); } sendResponse(hobaResponseEncoded): void { @@ -62,13 +65,16 @@ export class AuthService { }; fetch(environment.cicMetaUrl, options).then(response => { if (response.status === 401) { - return Promise.reject({ statusText: response.statusText }); + return Promise.reject({ + status: response.status, + statusText: response.statusText + }); } this.sessionToken = response.headers.get('Token'); sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken); this.setState('Click button to log in'); return; - }).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error})); + }); } async getChallenge(): Promise { @@ -77,7 +83,13 @@ export class AuthService { const authHeader = response.headers.get('WWW-Authenticate'); return hobaParseChallengeHeader(authHeader); } - }).catch(error => this.loggingService.sendErrorLevelMessage('Fetching challenge failed', this, {error})); + if (!response.ok) { + return Promise.reject({ + status: response.status, + statusText: response.statusText + }); + } + }); } async passwordLogin(password: string): Promise { @@ -85,8 +97,9 @@ export class AuthService { const o = await this.getChallenge(); await this.loginResponse(o, password); return true; - } catch (e) { - this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e}); + } catch (error) { + this.loggingService.sendErrorLevelMessage(`Login challenge failed: Error ${error.status} - ${error.statusText}`, + this, {error}); } return false; } @@ -96,8 +109,9 @@ export class AuthService { try { this.getWithToken(); return true; - } catch (e) { - this.loggingService.sendErrorLevelMessage('Login token failed', this, {error: e}); + } catch (error) { + this.loggingService.sendErrorLevelMessage(`Login token failed: Error ${error.status} - ${error.statusText}`, + this, {error}); } } return false; @@ -110,6 +124,10 @@ export class AuthService { this.sendResponse(r); } catch (error) { this.errorDialogService.openDialog({message: 'Incorrect key passphrase.'}); + return Promise.reject({ + status: error.status, + statusText: error.statusText + }); } } diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index 2bf7c89..5dc8a18 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -1,4 +1,4 @@ -import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; +import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {CustomErrorStateMatcher} from '@app/_helpers'; import {AuthService} from '@app/_services'; @@ -22,7 +22,8 @@ export class AuthComponent implements OnInit { constructor( private authService: AuthService, private formBuilder: FormBuilder, - private router: Router + private router: Router, + private cdr: ChangeDetectorRef, ) { } async ngOnInit(): Promise { @@ -57,6 +58,7 @@ export class AuthComponent implements OnInit { this.passwordInput(); } this.keyFormLoading = false; + this.cdr.detectChanges(); } async onPasswordInput(): Promise { @@ -70,6 +72,7 @@ export class AuthComponent implements OnInit { this.loginView(); } this.passwordFormLoading = false; + this.cdr.detectChanges(); } login(): void {