Skip to content

Commit

Permalink
chore: safe catch by verifying the appropriate error
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Dec 7, 2022
1 parent 110225c commit 426d8c6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,12 @@ class CartService extends TransactionBaseService {
{ cart_id: cartId, has_shipping: true },
{ has_shipping: false }
)
.catch(() => void 0)
.catch((err: Error) => {
// We only want to catch the errors related to not found items since we don't care if there is not item to update
if (!err.message?.endsWith("was not found")) {
throw err
}
})

cart = await this.retrieve(cart.id, {
relations: ["items", "discounts", "discounts.rule", "region"],
Expand Down Expand Up @@ -812,7 +817,12 @@ class CartService extends TransactionBaseService {
},
{ has_shipping: false }
)
.catch(() => void 0)
.catch((err: Error) => {
// We only want to catch the errors related to not found items since we don't care if there is not item to update
if (!err.message?.endsWith("was not found")) {
throw err
}
})

cart = await this.retrieve(cart.id, {
relations: ["items", "discounts", "discounts.rule", "region"],
Expand Down

0 comments on commit 426d8c6

Please sign in to comment.