![](/img/trans.png)
[英]How do i throw an exception and also execute the remaining business logic in the catch block?
[英]How do I throw Camunda business Error to out?
我关于抛出业务错误的问题。 例如,我有一些图表,并从Spring REST Controller的方法开始处理。 我怎样才能在test()方法中捕获“ Error-CheckNoneAZNOperationIsExist”并将其丢弃?
@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引擎“错误名称”装
上面代码的结果
{
"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.