Skip to content

Commit 2db3cb1

Browse files
committed
comment about moving error
1 parent 2fdf3ae commit 2db3cb1

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

integration-tests/http/__tests__/product-option/product-option.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,22 @@ medusaIntegrationTestRunner({
242242
})
243243
)
244244
})
245+
246+
it("should throw when trying to update an option that does not exist", async () => {
247+
const error = await api.post(
248+
`/admin/product-options/iDontExist`,
249+
{
250+
is_exclusive: false,
251+
},
252+
adminHeaders
253+
).catch((e) => e)
254+
255+
expect(error.response.status).toEqual(404)
256+
expect(error.response.data).toEqual({
257+
message: "Product option with id \"iDontExist\" not found",
258+
type: "not_found"
259+
})
260+
})
245261
})
246262

247263
describe("DELETE /admin/product-options/[id]", () => {

packages/core/core-flows/src/product/steps/update-product-options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
} from "@medusajs/framework/types"
55
import {
66
getSelectsAndRelationsFromObjectArray,
7+
MedusaError,
78
Modules,
89
} from "@medusajs/framework/utils"
910
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
@@ -49,6 +50,13 @@ export const updateProductOptionsStep = createStep(
4950
relations: ["values"],
5051
})
5152

53+
if (!prevData.length) {
54+
throw new MedusaError(
55+
MedusaError.Types.NOT_FOUND,
56+
`Product option with id "${data.selector.id}" not found`
57+
)
58+
}
59+
5260
const productOptions = await service.updateProductOptions(
5361
data.selector,
5462
data.update

packages/medusa/src/api/admin/product-options/[id]/route.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import {
1212
AdminUpdateProductOptionType,
1313
} from "../validators"
1414
import { HttpTypes } from "@medusajs/framework/types"
15-
import {
16-
ContainerRegistrationKeys,
17-
MedusaError,
18-
} from "@medusajs/framework/utils"
15+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
1916

2017
export const GET = async (
2118
req: AuthenticatedMedusaRequest<AdminGetProductOptionParamsType>,
@@ -37,29 +34,14 @@ export const POST = async (
3734
req: AuthenticatedMedusaRequest<AdminUpdateProductOptionType>,
3835
res: MedusaResponse<HttpTypes.AdminProductOptionResponse>
3936
) => {
40-
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
41-
const {
42-
data: [existingProductOption],
43-
} = await query.graph({
44-
entity: "product_option",
45-
filters: { id: req.params.id },
46-
fields: ["id"],
47-
})
48-
49-
if (!existingProductOption) {
50-
throw new MedusaError(
51-
MedusaError.Types.NOT_FOUND,
52-
`Product option with id "${req.params.id}" not found`
53-
)
54-
}
55-
5637
const { result } = await updateProductOptionsWorkflow(req.scope).run({
5738
input: {
5839
selector: { id: req.params.id },
5940
update: req.validatedBody,
6041
},
6142
})
6243

44+
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
6345
const {
6446
data: [product_option],
6547
} = await query.graph({

0 commit comments

Comments
 (0)