Skip to content

Commit

Permalink
refactor: revert breaking changes made in #17657 (#19036)
Browse files Browse the repository at this point in the history
In the past PR #17657 within this Epic branch, we made a lot of breaking changes. In that past PR we've also renamed public a lot of properties `public payload: any` to `public error: any` which was also a breaking change.

In this PR, we:
- revert those breaking changes.
  - bring back `public payload` property, if it was renamed to `public error`
  - bring back type `any` for `payload`/`error` properties that were changed to `ErrorActionType`
  - bring back the optional marker (`?`) for `payload`/`error`, that got removed the optional marker (`?`) 
  - bring back the old order of arguments of `EntityScopedFailAction`: `scope, error` vs `error, scope`
- additionally, we:
  - deprecate the signatures with the optional marker on the `payload`/`error` property, in favor of required params
  - widen type of `payload`/`error` to `any` from too-specific types like `ErrorModel`
  - pass missing `payload`/`error` parameter to super actions (like `ErrorActionType` etc.)
- fix some unit tests as a result of all above changes

Note for a reviewer:
The PR #19037 (not meant to be merged!) contains a full diff between this branch and the `develop` branch. You may want to check it to verify the current branch `feature/CXSPA-7198--v2` when merged to `epic/ssr-error-handling` will _really_ help to avoid _all_ breaking changes (related to ngrx actions) against `develop`

fixes https://jira.tools.sap/browse/CXSPA-7198
  • Loading branch information
Platonn authored Jul 11, 2024
1 parent 48f39f0 commit 84de0d1
Show file tree
Hide file tree
Showing 89 changed files with 563 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('Customer Actions', () => {
expect({ ...action }).toEqual({
type: AsmActions.CUSTOMER_SEARCH_FAIL,
meta: StateUtils.failMeta(CUSTOMER_SEARCH_DATA, error),
payload: error,
error,
});
});
Expand Down
8 changes: 4 additions & 4 deletions feature-libs/asm/core/store/actions/customer.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { CustomerSearchOptions, CustomerSearchPage } from '@spartacus/asm/root';
import { StateUtils, ErrorActionType } from '@spartacus/core';
import { StateUtils } from '@spartacus/core';
import {
CUSTOMER_LIST_CUSTOMERS_SEARCH_DATA,
CUSTOMER_SEARCH_DATA,
Expand Down Expand Up @@ -34,8 +34,8 @@ export class CustomerSearch extends StateUtils.LoaderLoadAction {

export class CustomerSearchFail extends StateUtils.LoaderFailAction {
readonly type = CUSTOMER_SEARCH_FAIL;
constructor(public error: ErrorActionType) {
super(CUSTOMER_SEARCH_DATA, error);
constructor(public payload: any) {
super(CUSTOMER_SEARCH_DATA, payload);
}
}

Expand All @@ -62,7 +62,7 @@ export class CustomerListCustomersSearch extends StateUtils.LoaderLoadAction {

export class CustomerListCustomersSearchFail extends StateUtils.LoaderFailAction {
readonly type = CUSTOMER_LIST_CUSTOMERS_SEARCH_FAIL;
constructor(public payload: ErrorActionType) {
constructor(public payload: any) {
super(CUSTOMER_LIST_CUSTOMERS_SEARCH_DATA, payload);
}
}
Expand Down
15 changes: 9 additions & 6 deletions feature-libs/cart/base/core/store/actions/cart-entry.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { OrderEntry } from '@spartacus/cart/base/root';
import { ErrorAction, ErrorActionType, StateUtils } from '@spartacus/core';
import { ErrorAction, StateUtils } from '@spartacus/core';
import { MULTI_CART_DATA } from '../multi-cart-state';

export const CART_ADD_ENTRY = '[Cart-entry] Add Entry';
Expand Down Expand Up @@ -60,7 +60,7 @@ export class CartAddEntryFail
extends StateUtils.EntityProcessesDecrementAction
implements ErrorAction
{
error: ErrorActionType = this.payload.error;
public error: any;
readonly type = CART_ADD_ENTRY_FAIL;

constructor(
Expand All @@ -74,6 +74,7 @@ export class CartAddEntryFail
}
) {
super(MULTI_CART_DATA, payload.cartId);
this.error = payload.error;
}
}

Expand Down Expand Up @@ -101,18 +102,19 @@ export class CartRemoveEntryFail
extends StateUtils.EntityProcessesDecrementAction
implements ErrorAction
{
error: ErrorActionType = this.payload.error;
public error: any;
readonly type = CART_REMOVE_ENTRY_FAIL;

constructor(
public payload: {
error: ErrorActionType;
error: any;
cartId: string;
userId: string;
entryNumber: string;
}
) {
super(MULTI_CART_DATA, payload.cartId);
this.error = payload.error;
}
}

Expand Down Expand Up @@ -154,12 +156,12 @@ export class CartUpdateEntryFail
extends StateUtils.EntityProcessesDecrementAction
implements ErrorAction
{
error: ErrorActionType = this.payload.error;
public error: any;
readonly type = CART_UPDATE_ENTRY_FAIL;

constructor(
public payload: {
error: ErrorActionType;
error: any;
userId: string;
cartId: string;
entryNumber: string;
Expand All @@ -169,6 +171,7 @@ export class CartUpdateEntryFail
}
) {
super(MULTI_CART_DATA, payload.cartId);
this.error = payload.error;
}
}

Expand Down
14 changes: 5 additions & 9 deletions feature-libs/cart/base/core/store/actions/cart-voucher.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {
ErrorAction,
ErrorActionType,
PROCESS_FEATURE,
StateUtils,
} from '@spartacus/core';
import { ErrorAction, PROCESS_FEATURE, StateUtils } from '@spartacus/core';
import { ADD_VOUCHER_PROCESS_ID, MULTI_CART_DATA } from '../multi-cart-state';

export const CART_ADD_VOUCHER = '[Cart-voucher] Add Cart Vouchers';
Expand Down Expand Up @@ -43,7 +38,7 @@ export class CartAddVoucherFail extends StateUtils.EntityFailAction {
userId: string;
cartId: string;
voucherId: string;
error: ErrorActionType;
error: any;
}
) {
super(PROCESS_FEATURE, ADD_VOUCHER_PROCESS_ID, payload.error);
Expand Down Expand Up @@ -86,18 +81,19 @@ export class CartRemoveVoucherFail
extends StateUtils.EntityProcessesDecrementAction
implements ErrorAction
{
error: ErrorActionType = this.payload.error;
public error: any;
readonly type = CART_REMOVE_VOUCHER_FAIL;

constructor(
public payload: {
error: ErrorActionType;
error: any;
cartId: string;
userId: string;
voucherId: string;
}
) {
super(MULTI_CART_DATA, payload.cartId);
this.error = payload.error;
}
}

Expand Down
19 changes: 10 additions & 9 deletions feature-libs/cart/base/core/store/actions/cart.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Action } from '@ngrx/store';
import { Cart } from '@spartacus/cart/base/root';
import { StateUtils, ErrorAction, ErrorActionType } from '@spartacus/core';
import { ErrorAction, StateUtils } from '@spartacus/core';
import { MULTI_CART_DATA } from '../multi-cart-state';

export const CREATE_CART = '[Cart] Create Cart';
Expand Down Expand Up @@ -55,7 +55,7 @@ export class CreateCart extends StateUtils.EntityLoadAction {
}

interface CreateCartFailPayload extends CreateCartPayload {
error: ErrorActionType;
error: any;
}

export class CreateCartFail extends StateUtils.EntityFailAction {
Expand Down Expand Up @@ -90,17 +90,18 @@ export class AddEmailToCartFail
extends StateUtils.EntityProcessesDecrementAction
implements ErrorAction
{
error: ErrorActionType = this.payload.error;
public error: any;
readonly type = ADD_EMAIL_TO_CART_FAIL;
constructor(
public payload: {
userId: string;
cartId: string;
error: ErrorActionType;
error: any;
email: string;
}
) {
super(MULTI_CART_DATA, payload.cartId);
this.error = payload.error;
}
}

Expand Down Expand Up @@ -129,7 +130,7 @@ export class LoadCart extends StateUtils.EntityLoadAction {
}

interface LoadCartFailPayload extends LoadCartPayload {
error: ErrorActionType;
error: any;
}

export class LoadCartFail extends StateUtils.EntityFailAction {
Expand Down Expand Up @@ -225,11 +226,11 @@ export class DeleteCartSuccess extends StateUtils.EntityRemoveAction {
}

export class DeleteCartFail implements ErrorAction {
error: ErrorActionType = this.payload.error;
public error: any;
readonly type = DELETE_CART_FAIL;
constructor(
public payload: { userId: string; cartId: string; error: ErrorActionType }
) {}
constructor(public payload: { userId: string; cartId: string; error: any }) {
this.error = payload.error;
}
}

export type CartAction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { MULTI_CART_DATA } from '@spartacus/cart/base/core';
import { ErrorActionType, PROCESS_FEATURE, StateUtils } from '@spartacus/core';
import { PROCESS_FEATURE, StateUtils } from '@spartacus/core';
import {
SAVED_CART_CLONE_CART_PROCESS_ID,
SAVED_CART_LIST_PROCESS_ID,
Expand Down Expand Up @@ -106,7 +106,7 @@ export class LoadSavedCartsFail extends StateUtils.EntityFailAction {
constructor(
public payload: {
userId: string;
error: ErrorActionType;
error: any;
}
) {
super(PROCESS_FEATURE, SAVED_CART_LIST_PROCESS_ID, payload.error);
Expand Down Expand Up @@ -154,7 +154,7 @@ export class RestoreSavedCartFail extends StateUtils.EntityFailAction {
public payload: {
userId: string;
cartId: string;
error: ErrorActionType;
error: any;
}
) {
super(PROCESS_FEATURE, SAVED_CART_RESTORE_CART_PROCESS_ID, payload.error);
Expand Down Expand Up @@ -208,7 +208,7 @@ export class SaveCartFail extends StateUtils.EntityFailAction {
cartId: string;
saveCartName?: string;
saveCartDescription?: string;
error: ErrorActionType;
error: any;
}
) {
super(PROCESS_FEATURE, SAVED_CART_SAVE_CART_PROCESS_ID, payload.error);
Expand Down Expand Up @@ -262,7 +262,7 @@ export class EditSavedCartFail extends StateUtils.EntityFailAction {
cartId: string;
saveCartName?: string;
saveCartDescription?: string;
error: ErrorActionType;
error: any;
}
) {
super(PROCESS_FEATURE, SAVED_CART_SAVE_CART_PROCESS_ID, payload.error);
Expand Down Expand Up @@ -305,7 +305,7 @@ export class CloneSavedCartFail extends StateUtils.EntityFailAction {
userId: string;
cartId: string;
saveCartName?: string;
error: ErrorActionType;
error: any;
}
) {
super(PROCESS_FEATURE, SAVED_CART_CLONE_CART_PROCESS_ID, payload.error);
Expand Down
17 changes: 13 additions & 4 deletions feature-libs/cart/wish-list/core/store/actions/wish-list.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Action } from '@ngrx/store';
import { MULTI_CART_DATA } from '@spartacus/cart/base/core';
import { Cart } from '@spartacus/cart/base/root';
import { ErrorActionType, StateUtils } from '@spartacus/core';
import { StateUtils } from '@spartacus/core';

export const CREATE_WISH_LIST = '[Wish List] Create Wish List';
export const CREATE_WISH_LIST_FAIL = '[Wish List] Create Wish List Fail';
Expand Down Expand Up @@ -39,8 +39,17 @@ export class CreateWishListSuccess extends StateUtils.EntitySuccessAction {

export class CreateWishListFail extends StateUtils.EntityFailAction {
readonly type = CREATE_WISH_LIST_FAIL;

constructor(public payload: { cartId: string; error: ErrorActionType }) {
constructor(payload: { cartId: string; error: any });
/**
* @deprecated Please pass the argument `error`.
* It will become mandatory along with removing
* the feature toggle `ssrStrictErrorHandlingForHttpAndNgrx`.
*/
constructor(
// eslint-disable-next-line @typescript-eslint/unified-signatures
payload: { cartId: string }
);
constructor(public payload: { cartId: string; error?: any }) {
super(MULTI_CART_DATA, payload.cartId, payload.error);
}
}
Expand Down Expand Up @@ -79,7 +88,7 @@ interface LoadWishListFailPayload {
* temporary cart used to track loading/error state or to normal wish list entity.
*/
cartId: string;
error: ErrorActionType;
error: any;
}

export class LoadWishListFail extends StateUtils.EntityFailAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Consignment Tracking Actions', () => {

expect({ ...action }).toEqual({
type: fromAction.LOAD_CONSIGNMENT_TRACKING_FAIL,
payload: error,
error,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { Action } from '@ngrx/store';
import { ErrorAction } from '@spartacus/core';
import { ConsignmentTracking } from '@spartacus/order/root';
import { ErrorAction, ErrorActionType } from '@spartacus/core';

export const LOAD_CONSIGNMENT_TRACKING = '[Order] Load Consignment Tracking';
export const LOAD_CONSIGNMENT_TRACKING_FAIL =
Expand All @@ -29,8 +29,11 @@ export class LoadConsignmentTracking implements Action {

export class LoadConsignmentTrackingFail implements ErrorAction {
readonly type = LOAD_CONSIGNMENT_TRACKING_FAIL;
public error: any;

constructor(public error: ErrorActionType) {}
constructor(public payload: any) {
this.error = payload;
}
}

export class LoadConsignmentTrackingSuccess implements Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Order Details Actions', () => {

expect({ ...action }).toEqual({
type: OrderActions.LOAD_ORDER_DETAILS_FAIL,
payload: error,
error,
meta: StateUtils.failMeta(ORDER_DETAILS, error),
});
Expand Down Expand Up @@ -86,6 +87,7 @@ describe('Order Details Actions', () => {

expect({ ...action }).toEqual({
type: OrderActions.CANCEL_ORDER_FAIL,
payload: error,
error,
meta: StateUtils.entityFailMeta(
PROCESS_FEATURE,
Expand Down
10 changes: 5 additions & 5 deletions feature-libs/order/core/store/actions/order-details.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { PROCESS_FEATURE, StateUtils, ErrorActionType } from '@spartacus/core';
import { PROCESS_FEATURE, StateUtils } from '@spartacus/core';
import {
CancellationRequestEntryInputList,
Order,
Expand Down Expand Up @@ -35,8 +35,8 @@ export class LoadOrderDetails extends StateUtils.LoaderLoadAction {

export class LoadOrderDetailsFail extends StateUtils.LoaderFailAction {
readonly type = LOAD_ORDER_DETAILS_FAIL;
constructor(public error: ErrorActionType) {
super(ORDER_DETAILS, error);
constructor(public payload: any) {
super(ORDER_DETAILS, payload);
}
}

Expand Down Expand Up @@ -69,8 +69,8 @@ export class CancelOrder extends StateUtils.EntityLoadAction {

export class CancelOrderFail extends StateUtils.EntityFailAction {
readonly type = CANCEL_ORDER_FAIL;
constructor(public error: ErrorActionType) {
super(PROCESS_FEATURE, CANCEL_ORDER_PROCESS_ID, error);
constructor(public payload: any) {
super(PROCESS_FEATURE, CANCEL_ORDER_PROCESS_ID, payload);
}
}

Expand Down
Loading

0 comments on commit 84de0d1

Please sign in to comment.