Verified Commit 6af5b11d authored by Raphael Ochsenbein's avatar Raphael Ochsenbein
Browse files

More consequently remove console.log, add api error output

parent 713a0b37
Pipeline #659 passed with stages
in 1 minute and 44 seconds
......@@ -13,9 +13,15 @@
<button [ibmButton]="'primary'" [size]="'normal'" (click)="check2FA()">Check 2FA</button>
<button [ibmButton]="'danger--primary'" [size]="'normal'" (click)="loginPopup2fA()">Login Request 2FA</button>
<hr/>
<ng-container *ngIf="error && (error.signInError || error.silentRenewError)">
<h2>Error</h2>
<ibm-code-snippet display="multi">{{ error | json }}</ibm-code-snippet>
<ng-container *ngIf="oidcError && (oidcError.signInError || oidcError.silentRenewError)">
<h2>OIDC Error</h2>
<ibm-code-snippet display="multi">{{ oidcError | json }}</ibm-code-snippet>
<hr/>
</ng-container>
<ng-container *ngIf="apiError">
<h2>API Error</h2>
<ibm-code-snippet display="multi">{{ apiError | json }}</ibm-code-snippet>
<hr/>
</ng-container>
......
import {Component, OnDestroy} from '@angular/core';
import { OidcFacade} from 'ng-oidc-client';
import {ToastService} from './toast';
import {merge, Observable, of, Subscription} from 'rxjs';
import {catchError, mergeMap, take} from 'rxjs/operators';
import { Component, OnDestroy } from '@angular/core';
import { OidcFacade } from 'ng-oidc-client';
import { ToastService } from './toast';
import { Observable, of, Subscription } from 'rxjs';
import {catchError, tap} from 'rxjs/operators';
import { environment } from '.././environments/environment';
import {HttpClient} from '@angular/common/http';
import {isArray} from 'util';
import {User as OidcUser} from 'oidc-client';
import {ErrorState} from 'ng-oidc-client/lib/reducers/oidc.reducer';
import { HttpClient } from '@angular/common/http';
import { User as OidcUser } from 'oidc-client';
import { ErrorState } from 'ng-oidc-client/lib/reducers/oidc.reducer';
@Component({
selector: 'app-root',
......@@ -20,7 +19,8 @@ export class AppComponent implements OnDestroy {
title = 'openid-connect-playground';
identity: OidcUser;
error: ErrorState;
oidcError: ErrorState;
apiError: any;
loadingSub: Subscription;
expiringSub: Subscription;
......@@ -56,7 +56,7 @@ export class AppComponent implements OnDestroy {
});
this.errorSub = this.oidcFacade.errors$.subscribe((data) => {
this.error = data;
this.oidcError = data;
if (data && (data.silentRenewError || data.signInError)) {
this.toast.show({
......@@ -73,6 +73,9 @@ export class AppComponent implements OnDestroy {
}
loginPopup() {
this.apiError = null;
this.oidcError = null;
this.toast.show({
type: 'info',
title: 'Log In',
......@@ -85,6 +88,9 @@ export class AppComponent implements OnDestroy {
}
logoutPopup() {
this.apiError = null;
this.oidcError = null;
this.toast.show({
type: 'warn',
title: 'Log Out',
......@@ -139,6 +145,9 @@ export class AppComponent implements OnDestroy {
}
loginPopup2fA() {
this.apiError = null;
this.oidcError = null;
this.toast.show({
type: 'warn',
title: 'Log In',
......@@ -173,8 +182,13 @@ export class AppComponent implements OnDestroy {
urlCall(api: Observable<{}>) {
api.pipe(
tap(() => {
this.apiError = null;
this.oidcError = null;
}),
catchError((error) => {
console.log('api error', error);
this.apiError = error;
this.toast.show({
type: 'error',
title: 'API Call Error',
......@@ -184,7 +198,6 @@ export class AppComponent implements OnDestroy {
})
).subscribe((data) => {
if (data) {
console.log('api data', data);
this.toast.show({
type: 'success',
title: 'API Call',
......
......@@ -10,8 +10,6 @@ export class OidcGuardService implements CanActivate {
return this.oidcFacade.identity$.pipe(
take(1),
switchMap(user => {
console.log('Auth Guard - Checking if user exists', user);
console.log('Auth Guard - Checking if user is expired:', user && user.expired);
if (user && !user.expired) {
return of(true);
} else {
......
......@@ -63,7 +63,7 @@ export class ToastService {
}
catchAndNotifyGenericError<T>(
title = 'An error has occurred',
title = 'An oidcError has occurred',
message = '',
callback: () => any = () => undefined
): MonoTypeOperatorFunction<T> {
......@@ -77,12 +77,12 @@ export class ToastService {
}
catchAndNotifyDataLoadingError<T>(callback?: () => any): MonoTypeOperatorFunction<T> {
return this.catchAndNotifyGenericError<T>('An error has occurred', 'Data could not be loaded', callback);
return this.catchAndNotifyGenericError<T>('An oidcError has occurred', 'Data could not be loaded', callback);
}
catchAndNotifyActionError<T>(action?: string, callback?: () => any): MonoTypeOperatorFunction<T> {
return this.catchAndNotifyGenericError<T>(
'An error has occurred',
'An oidcError has occurred',
action
? `Could not ${action}`
: 'The action could not be completed.',
......
......@@ -21,14 +21,13 @@ export class ToastService {
private parentInjector: Injector,
@Inject(_TOAST_CONFIG_TOKEN) private toastConfig: MyToastConfig,
) {
// console.log(parentInjector, this.toastConfig);
// somehow empty injection of the config... maybe issue with carbon?
this.toastConfig = {...defaultToastConfig, ...this.toastConfig };
this.lastToastTime = performance.now();
this.toastsSubject.pipe(
delayWhen((data) => {
delayWhen(() => {
const current = performance.now();
const diff = (current - this.lastToastTime) > 100;
if (diff) {
......
......@@ -8,9 +8,9 @@ export const environment = {
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
* to ignore zone related oidcError stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
* on performance if an oidcError is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
// import 'zone.js/dist/zone-oidcError'; // Included with Angular CLI.
......@@ -11,7 +11,6 @@ body {
}
// fixes
.bx--snippet--multi {
background: #1d1d1d;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment