Skip to content

Commit

Permalink
improved punchout error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shauke committed Mar 29, 2021
1 parent e5863ba commit c86c274
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/app/core/facades/account.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
loadUserPaymentMethods,
loginUser,
loginUserWithToken,
logoutUser,
requestPasswordReminder,
resetPasswordReminder,
updateCustomer,
Expand Down Expand Up @@ -85,6 +86,10 @@ export class AccountFacade {
this.store.dispatch(loginUserWithToken({ token }));
}

logoutUser() {
this.store.dispatch(logoutUser());
}

createUser(body: CustomerRegistrationType) {
this.store.dispatch(createUser(body));
}
Expand Down
31 changes: 22 additions & 9 deletions src/app/extensions/punchout/pages/punchout/punchout-page.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
import { of, race, throwError } from 'rxjs';
import { catchError, concatMap, mapTo, switchMap, take, tap } from 'rxjs/operators';
import { catchError, concatMap, delay, first, mapTo, switchMap, take, tap } from 'rxjs/operators';

import { AccountFacade } from 'ish-core/facades/account.facade';
import { AppFacade } from 'ish-core/facades/app.facade';
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { ApiTokenService } from 'ish-core/utils/api-token/api-token.service';
import { CookiesService } from 'ish-core/utils/cookies/cookies.service';
import { whenTruthy } from 'ish-core/utils/operators';

Expand All @@ -19,6 +20,7 @@ export class PunchoutPageGuard implements CanActivate {
private appFacade: AppFacade,
private accountFacade: AccountFacade,
private checkoutFacade: CheckoutFacade,
private apiTokenService: ApiTokenService,
private cookiesService: CookiesService,
private punchoutService: PunchoutService,
@Inject(PLATFORM_ID) private platformId: string
Expand Down Expand Up @@ -126,16 +128,27 @@ export class PunchoutPageGuard implements CanActivate {
return of(this.router.parseUrl('/home'));
}
}
})
)
).pipe(
catchError(error =>
of(this.router.parseUrl('/error')).pipe(
tap(() => {
this.appFacade.setBusinessError(error);
})
}),
// punchout error after successful authentication (needs to logout)
catchError(error =>
this.accountFacade.userLoading$.pipe(
first(loading => !loading),
delay(0),
switchMap(() => {
this.accountFacade.logoutUser();
this.apiTokenService.removeApiToken();
this.appFacade.setBusinessError(error);
return of(this.router.parseUrl('/error'));
})
)
)
)
).pipe(
// general punchout error handling (parameter missing, authentication error)
catchError(error => {
this.appFacade.setBusinessError(error);
return of(this.router.parseUrl('/error'));
})
);
}
}

1 comment on commit c86c274

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Demo Servers are available:

Please sign in to comment.