Skip to content

Commit 32eaa9d

Browse files
authored
fix(medusa): avoid throwing on error on set step failure endpoint (#14066)
* Avoid throwing on setStepFailure endpoint * Add changeset * Add tests
1 parent beb91d8 commit 32eaa9d

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

.changeset/humble-weeks-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/medusa": patch
3+
---
4+
5+
fix(medusa): avoid throwing on error on set step failure endpoint

integration-tests/http/__tests__/workflow-engine/admin/index.spec.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
WorkflowResponse,
77
} from "@medusajs/framework/workflows-sdk"
88
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
9-
import { Modules } from "@medusajs/utils"
9+
import { Modules, TransactionState } from "@medusajs/utils"
1010
import {
1111
adminHeaders,
1212
createAdminUser,
@@ -95,6 +95,54 @@ medusaIntegrationTestRunner({
9595
})
9696
})
9797

98+
describe("POST /admin/workflow-execution/[workflow_id]/steps/failure", function () {
99+
it("should set step as failed", async () => {
100+
const stepId = 'test-step'
101+
const step = createStep({
102+
name: stepId,
103+
async: true,
104+
}, () => { })
105+
106+
const workflowId = 'test-workflow'
107+
createWorkflow({
108+
name: workflowId,
109+
retentionTime: 60,
110+
}, () => {
111+
step()
112+
return new WorkflowResponse(void 0)
113+
})
114+
115+
const transactionId = "test-transaction"
116+
const engine = container.resolve(Modules.WORKFLOW_ENGINE) as IWorkflowEngineService
117+
await engine.run(workflowId, {
118+
transactionId
119+
})
120+
let workflowDetail = (await api.get(`/admin/workflows-executions/${workflowId}/${transactionId}`, adminHeaders)).data.workflow_execution
121+
122+
expect(workflowDetail.state).toBe(TransactionState.INVOKING)
123+
124+
const setFailureResponse = await api.post(`/admin/workflows-executions/${workflowId}/steps/failure`, {
125+
transaction_id: transactionId,
126+
step_id: stepId
127+
}, adminHeaders)
128+
129+
expect(setFailureResponse.status).toBe(200)
130+
expect(setFailureResponse.data).toEqual(
131+
expect.objectContaining({
132+
success: true,
133+
})
134+
)
135+
136+
workflowDetail = (await api.get(`/admin/workflows-executions/${workflowId}/${transactionId}`, adminHeaders)).data.workflow_execution
137+
138+
expect(workflowDetail).toEqual(
139+
expect.objectContaining({
140+
state: TransactionState.REVERTED,
141+
})
142+
)
143+
})
144+
})
145+
98146
describe("Workflow Orchestrator module subscribe", function () {
99147
it("should subscribe to a workflow and receive the response when it finishes", async () => {
100148
const step1 = createStep({ name: "step1" }, async () => {

packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export const POST = async (
4545
context: {
4646
requestId: req.requestId,
4747
},
48+
throwOnError: false,
49+
logOnError: true,
4850
},
4951
})
5052

0 commit comments

Comments
 (0)