Escalate errors to higher level handlers.
This commit is contained in:
parent
53ed56460c
commit
63cff19bae
@ -45,10 +45,13 @@ export class AuthService {
|
|||||||
};
|
};
|
||||||
fetch(environment.cicMetaUrl, options).then(response => {
|
fetch(environment.cicMetaUrl, options).then(response => {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
return Promise.reject({ statusText: response.statusText });
|
return Promise.reject({
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sendResponse(hobaResponseEncoded): void {
|
sendResponse(hobaResponseEncoded): void {
|
||||||
@ -62,13 +65,16 @@ export class AuthService {
|
|||||||
};
|
};
|
||||||
fetch(environment.cicMetaUrl, options).then(response => {
|
fetch(environment.cicMetaUrl, options).then(response => {
|
||||||
if (response.status === 401) {
|
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');
|
this.sessionToken = response.headers.get('Token');
|
||||||
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken);
|
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken);
|
||||||
this.setState('Click button to log in');
|
this.setState('Click button to log in');
|
||||||
return;
|
return;
|
||||||
}).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChallenge(): Promise<any> {
|
async getChallenge(): Promise<any> {
|
||||||
@ -77,7 +83,13 @@ export class AuthService {
|
|||||||
const authHeader = response.headers.get('WWW-Authenticate');
|
const authHeader = response.headers.get('WWW-Authenticate');
|
||||||
return hobaParseChallengeHeader(authHeader);
|
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<boolean> {
|
async passwordLogin(password: string): Promise<boolean> {
|
||||||
@ -85,8 +97,9 @@ export class AuthService {
|
|||||||
const o = await this.getChallenge();
|
const o = await this.getChallenge();
|
||||||
await this.loginResponse(o, password);
|
await this.loginResponse(o, password);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e});
|
this.loggingService.sendErrorLevelMessage(`Login challenge failed: Error ${error.status} - ${error.statusText}`,
|
||||||
|
this, {error});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -96,8 +109,9 @@ export class AuthService {
|
|||||||
try {
|
try {
|
||||||
this.getWithToken();
|
this.getWithToken();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
this.loggingService.sendErrorLevelMessage('Login token failed', this, {error: e});
|
this.loggingService.sendErrorLevelMessage(`Login token failed: Error ${error.status} - ${error.statusText}`,
|
||||||
|
this, {error});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -110,6 +124,10 @@ export class AuthService {
|
|||||||
this.sendResponse(r);
|
this.sendResponse(r);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.errorDialogService.openDialog({message: 'Incorrect key passphrase.'});
|
this.errorDialogService.openDialog({message: 'Incorrect key passphrase.'});
|
||||||
|
return Promise.reject({
|
||||||
|
status: error.status,
|
||||||
|
statusText: error.statusText
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||||
import {CustomErrorStateMatcher} from '@app/_helpers';
|
import {CustomErrorStateMatcher} from '@app/_helpers';
|
||||||
import {AuthService} from '@app/_services';
|
import {AuthService} from '@app/_services';
|
||||||
@ -22,7 +22,8 @@ export class AuthComponent implements OnInit {
|
|||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private router: Router
|
private router: Router,
|
||||||
|
private cdr: ChangeDetectorRef,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
@ -57,6 +58,7 @@ export class AuthComponent implements OnInit {
|
|||||||
this.passwordInput();
|
this.passwordInput();
|
||||||
}
|
}
|
||||||
this.keyFormLoading = false;
|
this.keyFormLoading = false;
|
||||||
|
this.cdr.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPasswordInput(): Promise<void> {
|
async onPasswordInput(): Promise<void> {
|
||||||
@ -70,6 +72,7 @@ export class AuthComponent implements OnInit {
|
|||||||
this.loginView();
|
this.loginView();
|
||||||
}
|
}
|
||||||
this.passwordFormLoading = false;
|
this.passwordFormLoading = false;
|
||||||
|
this.cdr.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
login(): void {
|
login(): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user