fix(medusa): In product isolation, throw if product not found (#5224)

**What**
Throw not found error if product does not exists
This commit is contained in:
Adrien de Peretti
2023-09-27 14:41:50 +02:00
committed by GitHub
parent 4c8836b488
commit c68ba63c1b
3 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): In product isolation, throw if product not found

View File

@@ -1,6 +1,7 @@
import { PricingService, ProductService } from "../../../../services"
import IsolateProductDomainFeatureFlag from "../../../../loaders/feature-flags/isolate-product-domain"
import { defaultAdminProductRemoteQueryObject } from "./index"
import { MedusaError } from "@medusajs/utils"
/**
* @oas [get] /admin/products/{id}
@@ -100,6 +101,13 @@ async function getProductWithIsolatedProductModule(req, id, retrieveConfig) {
const [product] = await remoteQuery(query)
if (!product) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Product with id: ${id} not found`
)
}
product.profile_id = product.profile?.id
return product

View File

@@ -11,6 +11,7 @@ import { PriceSelectionParams } from "../../../../types/price-selection"
import { cleanResponseData } from "../../../../utils"
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
import { defaultStoreProductRemoteQueryObject } from "./index"
import { MedusaError } from "@medusajs/utils"
/**
* @oas [get] /store/products/{id}
@@ -176,6 +177,13 @@ async function getProductWithIsolatedProductModule(req, id: string) {
const [product] = await remoteQuery(query)
if (!product) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Product with id: ${id} not found`
)
}
product.profile_id = product.profile?.id
return product