Lint code.

This commit is contained in:
Spencer Ofwiti 2021-06-30 19:20:47 +03:00
parent 0a2c088036
commit 28fc0048f7
3 changed files with 30 additions and 25 deletions

View File

@ -14,7 +14,7 @@ import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators'; import { catchError } from 'rxjs/operators';
// Application imports // Application imports
import { LoggingService } from '@app/_services'; import { ErrorDialogService, LoggingService } from '@app/_services';
/** Intercepts and handles errors from outgoing HTTP request. */ /** Intercepts and handles errors from outgoing HTTP request. */
@Injectable() @Injectable()
@ -22,10 +22,15 @@ export class ErrorInterceptor implements HttpInterceptor {
/** /**
* Initialization of the error interceptor. * 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 loggingService - A service that provides logging capabilities.
* @param router - A service that provides navigation among views and URL manipulation 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. * Intercepts HTTP requests.
@ -54,9 +59,10 @@ export class ErrorInterceptor implements HttpInterceptor {
this.router.navigateByUrl('/auth').then(); this.router.navigateByUrl('/auth').then();
break; break;
case 403: // forbidden case 403: // forbidden
this.errorDialogService.openDialog( this.errorDialogService.openDialog({
{ message: 'Access to resource is not allowed (Error 403)'}) message: 'Access to resource is not allowed (Error 403)',
//alert('Access to resource is not allowed!'); });
// alert('Access to resource is not allowed!');
break; break;
} }
// Return an observable with a user-facing error message. // Return an observable with a user-facing error message.

View File

@ -46,7 +46,7 @@ export class AuthService {
} }
getWithToken(): Promise<boolean> { getWithToken(): Promise<boolean> {
const sessionToken = this.getSessionToken() const sessionToken = this.getSessionToken();
const headers = { const headers = {
Authorization: 'Bearer ' + sessionToken, Authorization: 'Bearer ' + sessionToken,
'Content-Type': 'application/json;charset=utf-8', 'Content-Type': 'application/json;charset=utf-8',
@ -96,29 +96,28 @@ export class AuthService {
const o = await this.getChallenge(); const o = await this.getChallenge();
const r = await signChallenge( const r = await signChallenge(
o.challenge, o.challenge,
o.realm, o.realm,
environment.cicMetaUrl, environment.cicMetaUrl,
this.mutableKeyStore this.mutableKeyStore
); );
const tokenResponse = await this.sendSignedChallenge(r) const tokenResponse = await this.sendSignedChallenge(r).then((response) => {
.then((response) => { const token = response.headers.get('Token');
const token = response.headers.get('Token'); if (token) {
if (token) { return token;
return token; }
} if (response.status === 401) {
if (response.status === 401) { throw new HttpError('You are not authorized to use this system', response.status);
throw new HttpError('You are not authorized to use this system', response.status); }
} if (!response.ok) {
if (!response.ok) { throw new HttpError('Unknown error from authentication server', response.status);
throw new HttpError('Unknown error from authentication server', response.status); }
}
}); });
if (tokenResponse) { if (tokenResponse) {
this.setSessionToken(tokenResponse); this.setSessionToken(tokenResponse);
//this.setState('Click button to log in'); // this.setState('Click button to log in');
return true; return true;
} }
return false; return false;

View File

@ -57,7 +57,7 @@ export class AuthComponent implements OnInit {
} }
} catch (HttpError) { } catch (HttpError) {
this.errorDialogService.openDialog({ this.errorDialogService.openDialog({
message: "Failed to login please try again.", message: 'Failed to login please try again.',
}); });
} }
} }