diff --git a/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts index 64d1af3639..200019dd75 100644 --- a/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts @@ -83,7 +83,7 @@ export default class extends Instruction { }; } catch (error) { return { - status: JOB_STATUS.FAILED, + status: config.ignoreFail ? JOB_STATUS.RESOLVED : JOB_STATUS.FAILED, result: error.isAxiosError ? error.toJSON() : error.message, }; } diff --git a/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts index 239c2cbd11..05ecc56fe2 100644 --- a/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts @@ -22,12 +22,6 @@ import { RequestConfig } from '../RequestInstruction'; const HOST = 'localhost'; -function getRandomPort() { - const minPort = 1024; - const maxPort = 49151; - return Math.floor(Math.random() * (maxPort - minPort + 1)) + minPort; -} - class MockAPI { app: Koa; server: Server; @@ -38,6 +32,9 @@ class MockAPI { get URL_400() { return `http://${HOST}:${this.port}/api/400`; } + get URL_404() { + return `http://${HOST}:${this.port}/api/404`; + } get URL_TIMEOUT() { return `http://${HOST}:${this.port}/api/timeout`; } @@ -408,11 +405,16 @@ describe('workflow > instructions > request', () => { }); describe('sync request', () => { - it('sync trigger', async () => { - const syncFlow = await WorkflowModel.create({ + let syncFlow; + + beforeEach(async () => { + syncFlow = await WorkflowModel.create({ type: 'syncTrigger', enabled: true, }); + }); + + it('sync trigger', async () => { await syncFlow.createNode({ type: 'request', config: { @@ -432,5 +434,24 @@ describe('workflow > instructions > request', () => { expect(job.status).toEqual(JOB_STATUS.RESOLVED); expect(job.result).toEqual({ meta: {}, data: {} }); }); + + it('ignoreFail', async () => { + await syncFlow.createNode({ + type: 'request', + config: { + url: api.URL_404, + method: 'GET', + ignoreFail: true, + } as RequestConfig, + }); + + const workflowPlugin = app.pm.get(PluginWorkflow) as PluginWorkflow; + const processor = (await workflowPlugin.trigger(syncFlow, { data: { title: 't1' } })) as Processor; + + const [execution] = await syncFlow.getExecutions(); + const [job] = await execution.getJobs(); + expect(job.status).toBe(JOB_STATUS.RESOLVED); + expect(job.result.status).toBe(404); + }); }); });