fix(medusa): cart now returns 404 when not found (#13622)

FIXES #10218 
FIXES CORE-739
This commit is contained in:
William Bouchard
2025-09-30 02:49:17 -04:00
committed by GitHub
parent f970e1355a
commit 9d3c71fefd
3 changed files with 26 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"integration-tests-http": patch
---
fix(medusa): cart now returns 404 when not found

View File

@@ -9,11 +9,7 @@ import {
PromotionStatus,
PromotionType,
} from "@medusajs/utils"
import {
createAdminUser,
generatePublishableKey,
generateStoreHeaders,
} from "../../../../helpers/create-admin-user"
import { createAdminUser, generatePublishableKey, generateStoreHeaders, } from "../../../../helpers/create-admin-user"
import { setupTaxStructure } from "../../../../modules/__tests__/fixtures"
import { createAuthenticatedCustomer } from "../../../../modules/helpers/create-authenticated-customer"
import { medusaTshirtProduct } from "../../../__fixtures__/product"
@@ -152,6 +148,17 @@ medusaIntegrationTestRunner({
).data.promotion
})
describe("GET /store/carts/[id]", () => {
it("should return 404 when trying to fetch a cart that does not exist", async () => {
const response = await api.get(
`/store/carts/fake`,
storeHeadersWithCustomer
).catch((e) => e)
expect(response.response.status).toEqual(404)
})
})
describe("POST /store/carts", () => {
it("should successfully create a cart", async () => {
const response = await api.post(

View File

@@ -1,6 +1,7 @@
import { MedusaContainer } from "@medusajs/framework/types"
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/framework/utils"
@@ -18,5 +19,12 @@ export const refetchCart = async (
const [cart] = await remoteQuery(queryObject)
if (!cart) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Cart with id '${id}' not found`
)
}
return cart
}