簡體   English   中英

如何將Camunda Business Error丟出去?

[英]How do I throw Camunda business Error to out?

我關於拋出業務錯誤的問題。 例如,我有一些圖表,並從Spring REST Controller的方法開始處理。 我怎樣才能在test()方法中捕獲“ Error-CheckNoneAZNOperationIsExist”並將其丟棄?

Camunda流程圖

@RestController
public class TestEndpoint{
    @Autowired
    ProcessEngine processEngine;

    @GetMapping(path = "account-close")
    public String test(){
        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("account_close_flow");
        return "hi";
    }
}

最后,當發生“錯誤結束事件”時,我想向使用者拋出異常,例如JSON

{
    “errorMessage”: “CheckNoneAZNOperationIsExist”, 
    “errorCode”: 123 
}

最后,我找到了解決方案。

1)我向所有邊界事件添加了錯誤代碼變量(例如globalError

2)執行過程后,我檢查歷史變量實例(Camunda Java API)

@RestController
public class TestEndpoint{
    @Autowired
    ProcessEngine processEngine;

    @GetMapping(path = "x")
    public String test(){
        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("account_close_flow");
        HistoricVariableInstanceEntity variable = (HistoricVariableInstanceEntity) processEngine.getHistoryService()
                .createHistoricVariableInstanceQuery()
                .processInstanceId(processInstance.getId())
                .variableName("globalError").singleResult();
        if(variable != null)
           throw new ResponseStatusException(HttpStatus.BAD_REQUEST, processInstance.getId() +" "+variable.getTextValue());

        return "hi";
    }
}

3)當發生錯誤globalError由Camunda引擎“錯誤名稱”裝

Camunda圖示例

上面代碼的結果

{
    "timestamp": "2019-08-18T10:34:49.928+0000",
    "status": 400,
    "error": "Bad Request",
    "message": "ce72ca30-c1a3-11e9-bb0b-0a0027000005 ErrorUserIsFrozen",
    "path": "/x"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM