Detect error when adding item to cart #193
-
Hello everyone, I am currently working on the cart functionality using the As a result, the addItem method always returns a swell-js SDK version: try {
await addItem({
productId,
quantity: 1,
variantId,
});
// proceed with a positive scenario
} catch {
// handle error
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @wialy , what's the error/response you're seeing when using the addItem method? I take it it's not the standard error response (with code and message), else it would trigger the catch clause. |
Beta Was this translation helpful? Give feedback.
-
Hey @greph, Thanks for picking up the topic and sorry for my late response. The response comes with a 200 status code, however, the payload is:
It seems like the issue is not with the client SDK, maybe REST API should use different status for this kind of error. |
Beta Was this translation helpful? Give feedback.
@wialy Yes, you're right! It would return 200 status code and you could handle it using
response.errors
object to confirm if there's an error in placing an item in the cart.I would also take your feedback to replace it with error status codes (4xx) while versioning the API later.