diff --git a/.changeset/humble-weeks-tease.md b/.changeset/humble-weeks-tease.md new file mode 100644 index 0000000000..ad1d2c67bf --- /dev/null +++ b/.changeset/humble-weeks-tease.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): avoid throwing on error on set step failure endpoint diff --git a/integration-tests/http/__tests__/workflow-engine/admin/index.spec.ts b/integration-tests/http/__tests__/workflow-engine/admin/index.spec.ts index 6ffead6881..137dc22a11 100644 --- a/integration-tests/http/__tests__/workflow-engine/admin/index.spec.ts +++ b/integration-tests/http/__tests__/workflow-engine/admin/index.spec.ts @@ -6,7 +6,7 @@ import { WorkflowResponse, } from "@medusajs/framework/workflows-sdk" import { medusaIntegrationTestRunner } from "@medusajs/test-utils" -import { Modules } from "@medusajs/utils" +import { Modules, TransactionState } from "@medusajs/utils" import { adminHeaders, createAdminUser, @@ -95,6 +95,54 @@ medusaIntegrationTestRunner({ }) }) + describe("POST /admin/workflow-execution/[workflow_id]/steps/failure", function () { + it("should set step as failed", async () => { + const stepId = 'test-step' + const step = createStep({ + name: stepId, + async: true, + }, () => { }) + + const workflowId = 'test-workflow' + createWorkflow({ + name: workflowId, + retentionTime: 60, + }, () => { + step() + return new WorkflowResponse(void 0) + }) + + const transactionId = "test-transaction" + const engine = container.resolve(Modules.WORKFLOW_ENGINE) as IWorkflowEngineService + await engine.run(workflowId, { + transactionId + }) + let workflowDetail = (await api.get(`/admin/workflows-executions/${workflowId}/${transactionId}`, adminHeaders)).data.workflow_execution + + expect(workflowDetail.state).toBe(TransactionState.INVOKING) + + const setFailureResponse = await api.post(`/admin/workflows-executions/${workflowId}/steps/failure`, { + transaction_id: transactionId, + step_id: stepId + }, adminHeaders) + + expect(setFailureResponse.status).toBe(200) + expect(setFailureResponse.data).toEqual( + expect.objectContaining({ + success: true, + }) + ) + + workflowDetail = (await api.get(`/admin/workflows-executions/${workflowId}/${transactionId}`, adminHeaders)).data.workflow_execution + + expect(workflowDetail).toEqual( + expect.objectContaining({ + state: TransactionState.REVERTED, + }) + ) + }) + }) + describe("Workflow Orchestrator module subscribe", function () { it("should subscribe to a workflow and receive the response when it finishes", async () => { const step1 = createStep({ name: "step1" }, async () => { diff --git a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts index 3b75070f69..c04668c903 100644 --- a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts +++ b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts @@ -45,6 +45,8 @@ export const POST = async ( context: { requestId: req.requestId, }, + throwOnError: false, + logOnError: true, }, })