fix: guard calculatedPriceSet to avoid 500 instead of 400 on missing …#15936
Conversation
🦋 Changeset detectedLatest commit: d3f78e5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 80 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! A few items need to be addressed before this can move forward: The core fix is correct: adding the calculatedPriceSet guard prevents the TypeError (500) and lets the existing INVALID_DATA MedusaError (400) fire when a variant has no price in the cart's currency. prepareLineItemData handles the now-undefined unitPrice safely, and the integration test is well-scoped and uses in-scope fixtures. One required item: a changeset is missing for the packages/core/core-flows change (the checklist marks it done, but none is present). Minor, non-blocking: unrelated prettier/whitespace reformatting adds scope noise, and the linked issue is referenced without a closing
Triggered by: new PR opened |
|
Thanks for the contribution! A few items need to be addressed before this can move forward: The core fix is correct: the calculatedPriceSet guard prevents the 500 TypeError and lets the existing INVALID_DATA (400) error fire for variants unpriced in the cart's currency; the integration test is well-scoped and uses in-scope fixtures. One required change: the added changeset marks @medusajs/core-flows as 'major', which (per the changeset-bot) triggers a major version bump across ~80 packages. A bug fix should be a 'patch'. Minor, non-blocking: unrelated prettier/whitespace reformatting (two blank lines added around line 1123 of the test, and the variantIds/isCustomPrice reflow) adds sc
Triggered by: new commit pushed |
Fixes #15932
…price
Summary
What — What changes are introduced in this PR?
Fixed a bug where adding a cart line item for a variant with no price in the cart's region threw an unhandled 500 TypeError instead of the intended 400 validation error.
Why — Why are these changes relevant or necessary?
References issue #15932; it's a real production bug that surfaces as an opaque error to storefront clients.
How — How have these changes been implemented?
Added a calculatedPriceSet guard to the price-assignment branch so the already-collected priceNotFound list is actually used, letting the existing MedusaError be thrown as intended.
Testing — How have these changes been tested, or how can the reviewer test the feature?
I added an integration test in integration-tests/http/tests/cart/store/cart.spec.ts, under the POST /store/carts/:id/line-items describe block:
should throw a 400 error instead of a 500 when adding a variant that has no price in the cart's currency
The test creates a product with a price only in usd, creates a cart scoped to a EUR region, then attempts to add the unpriced variant as a line item. It asserts the response is a 400 with type: "invalid_data", rather than an unhandled 500.
I verified the fix locally by running the test both before and after applying the change:
Before the fix (reverted): the request throws an unhandled 500 TypeError: Cannot read properties of undefined (reading 'calculated_amount'), and the test fails as expected.
After the fix: the request returns the intended 400 validation error, and the test passes.
Checklist
Please ensure the following before requesting a review:
yarn changesetand follow the prompts