Skip to content

Commit

Permalink
add more identifiers & fix error
Browse files Browse the repository at this point in the history
 - 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`
  • Loading branch information
JanMolcik committed Dec 17, 2024
1 parent 0936a06 commit b652fda
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions storefront/utils/recommender/getRecommenderClientIdentifier.ts
Original file line number Diff line number Diff line change
@@ -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];
Expand Down

0 comments on commit b652fda

Please sign in to comment.