diff --git a/src/app/core/services/basket/basket.service.spec.ts b/src/app/core/services/basket/basket.service.spec.ts index 7698bcbba1..30929cb8e0 100644 --- a/src/app/core/services/basket/basket.service.spec.ts +++ b/src/app/core/services/basket/basket.service.spec.ts @@ -107,12 +107,6 @@ describe('Basket Service', () => { }); }); - it('should not throw errors when getting a basket by token is unsuccessful', done => { - when(apiService.get(anything(), anything())).thenReturn(throwError(() => new Error())); - - basketService.getBasketByToken('dummy').subscribe({ next: fail, error: fail, complete: done }); - }); - it("should create a basket data when 'createBasket' is called", done => { when(apiService.post(anything(), anything(), anything())).thenReturn(of(basketMockData)); diff --git a/src/app/core/services/basket/basket.service.ts b/src/app/core/services/basket/basket.service.ts index d65a72894a..a7ff3a5189 100644 --- a/src/app/core/services/basket/basket.service.ts +++ b/src/app/core/services/basket/basket.service.ts @@ -1,7 +1,7 @@ import { HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Store, select } from '@ngrx/store'; -import { EMPTY, Observable, forkJoin, iif, of, throwError } from 'rxjs'; +import { Observable, forkJoin, iif, of, throwError } from 'rxjs'; import { catchError, concatMap, first, map, take } from 'rxjs/operators'; import { AddressMapper } from 'ish-core/models/address/address.mapper'; @@ -213,12 +213,8 @@ export class BasketService { .get(`baskets/current`, { headers: this.basketHeaders.set(ApiService.TOKEN_HEADER_KEY, apiToken), params, - skipApiErrorHandling: true, }) - .pipe( - map(BasketMapper.fromData), - catchError(() => EMPTY) - ); + .pipe(map(BasketMapper.fromData)); } /** diff --git a/src/app/core/store/customer/basket/basket.actions.ts b/src/app/core/store/customer/basket/basket.actions.ts index 803b35c9b0..d6a44c1e76 100644 --- a/src/app/core/store/customer/basket/basket.actions.ts +++ b/src/app/core/store/customer/basket/basket.actions.ts @@ -26,6 +26,8 @@ export const loadBasketByAPIToken = createAction( payload<{ apiToken: string }>() ); +export const loadBasketByAPITokenFail = createAction('[Basket API] Load Basket by API Token Fail', httpError()); + export const loadBasketFail = createAction('[Basket API] Load Basket Fail', httpError()); export const loadBasketSuccess = createAction('[Basket API] Load Basket Success', payload<{ basket: Basket }>()); diff --git a/src/app/core/store/customer/basket/basket.effects.ts b/src/app/core/store/customer/basket/basket.effects.ts index ab45ca9d36..e7e2ee9cb6 100644 --- a/src/app/core/store/customer/basket/basket.effects.ts +++ b/src/app/core/store/customer/basket/basket.effects.ts @@ -38,6 +38,7 @@ import { deleteBasketAttributeSuccess, loadBasket, loadBasketByAPIToken, + loadBasketByAPITokenFail, loadBasketEligibleShippingMethods, loadBasketEligibleShippingMethodsFail, loadBasketEligibleShippingMethodsSuccess, @@ -116,7 +117,10 @@ export class BasketEffects { ofType(loadBasketByAPIToken), mapToPayloadProperty('apiToken'), concatMap(apiToken => - this.basketService.getBasketByToken(apiToken).pipe(map(basket => loadBasketSuccess({ basket }))) + this.basketService.getBasketByToken(apiToken).pipe( + map(basket => loadBasketSuccess({ basket })), + mapErrorToAction(loadBasketByAPITokenFail) + ) ) ) ); diff --git a/src/app/core/store/customer/basket/basket.reducer.ts b/src/app/core/store/customer/basket/basket.reducer.ts index 81133ee51a..435a5b2ab7 100644 --- a/src/app/core/store/customer/basket/basket.reducer.ts +++ b/src/app/core/store/customer/basket/basket.reducer.ts @@ -38,6 +38,7 @@ import { deleteBasketPaymentSuccess, loadBasket, loadBasketByAPIToken, + loadBasketByAPITokenFail, loadBasketEligiblePaymentMethods, loadBasketEligiblePaymentMethodsFail, loadBasketEligiblePaymentMethodsSuccess, @@ -149,7 +150,12 @@ export const basketReducer = createReducer( mergeBasketInProgress, setBasketDesiredDeliveryDate ), - unsetLoadingOn(addPromotionCodeToBasketSuccess, addPromotionCodeToBasketFail, loadBasketSuccess), + unsetLoadingOn( + addPromotionCodeToBasketSuccess, + addPromotionCodeToBasketFail, + loadBasketSuccess, + loadBasketByAPITokenFail + ), unsetLoadingAndErrorOn( mergeBasketSuccess, updateBasketItemSuccess,