From b652fdabc48951c5c787ad5425cb3e1abb847997 Mon Sep 17 00:00:00 2001 From: Jan Molcik Date: Tue, 17 Dec 2024 12:57:48 +0100 Subject: [PATCH] add more identifiers & fix error - to fix unhandled error, `logException` is used instead of throwing new Error on missing pathname in `RECOMMENDER_PATHNAMES` - added more pathname options from where a product may be added to cart, resulting in the `RecommendedProductsQuery` being refetched due to `AddToCartPopup` containing `DeferredRecommendedProducts` --- .../recommender/getRecommenderClientIdentifier.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/storefront/utils/recommender/getRecommenderClientIdentifier.ts b/storefront/utils/recommender/getRecommenderClientIdentifier.ts index 42d98edf12..5e56b36eac 100644 --- a/storefront/utils/recommender/getRecommenderClientIdentifier.ts +++ b/storefront/utils/recommender/getRecommenderClientIdentifier.ts @@ -1,13 +1,22 @@ +import { logException } from 'utils/errors/logException'; + const RECOMMENDER_PATHNAMES = { '/': 'homepage', - '/products/[productSlug]': 'product-detail', + '/blogArticles/[blogArticleSlug]': 'blog-article-detail', '/cart': 'cart', + '/categories/[categorySlug]': 'category-detail', + '/flags/[flagSlug]': 'flag-detail', + '/product-comparison': 'product-comparison', + '/products/[productSlug]': 'product-detail', + '/search': 'search', + '/wishlist': 'wishlist', } as const; export const getRecommenderClientIdentifier = (pathname: string): string => { const splitPathname = pathname.split('?')[0]; if (!(splitPathname in RECOMMENDER_PATHNAMES)) { - throw new Error(`Pathname ${splitPathname} does not have a corresponding recommender client identifier`); + logException(`Pathname ${splitPathname} does not have a corresponding identifier in RECOMMENDER_PATHNAMES`); + return splitPathname; } return RECOMMENDER_PATHNAMES[splitPathname as RecommenderClientIdentifierKeyType];