Skip to content

Commit

Permalink
fix: catch wishlist items 404 (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanilowicz authored Sep 17, 2023
1 parent 3520c26 commit 61de036
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-garlics-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-pwa/composables-next": patch
---

Catch 404 api error - `getWishlistProducts``
16 changes: 12 additions & 4 deletions packages/composables/src/useSyncWishlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
mergeWishlistProducts as mergeWishlistProductsAPI,
} from "@shopware-pwa/api-client";
import { useShopwareContext } from "./useShopwareContext";
import { ClientApiError } from "@shopware-pwa/types";

export type UseSyncWishlistReturn = {
/**
Expand Down Expand Up @@ -57,10 +58,17 @@ export function useSyncWishlist(): UseSyncWishlistReturn {
* Only for logged-in users
*/
async function getWishlistProducts() {
const response = await getWishlistProductsAPI(undefined, apiInstance);
_wishlistItems.value = [
...response.products.elements.map((element) => element.id),
];
try {
const response = await getWishlistProductsAPI(undefined, apiInstance);
_wishlistItems.value = [
...response.products.elements.map((element) => element.id),
];
} catch (e) {
const error = e as ClientApiError;
// If 404 ignore printing error and reset wishlist
if (error?.statusCode !== 404) console.error(error);
_wishlistItems.value = [];
}
}

async function mergeWishlistProducts(itemsToMerge: string[]) {
Expand Down

2 comments on commit 61de036

@vercel
Copy link

@vercel vercel bot commented on 61de036 Sep 17, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 61de036 Sep 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo.vercel.app
frontends-demo-shopware-frontends.vercel.app
frontends-demo-git-main-shopware-frontends.vercel.app

Please sign in to comment.