[英]How do I throw Camunda business Error to out?
My question about throwing a business error to out. 我关于抛出业务错误的问题。 For example, I have the some diagram and I start the process from method of Spring REST Controller. 例如,我有一些图表,并从Spring REST Controller的方法开始处理。 How I can catch "Error-CheckNoneAZNOperationIsExist" in test() method and throw it to out? 我怎样才能在test()方法中捕获“ Error-CheckNoneAZNOperationIsExist”并将其丢弃?
Camunda process diagram 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";
}
}
Finally, I want to throw an exception to the consumer, when “Error End Event” is occurred, for example as JSON 最后,当发生“错误结束事件”时,我想向使用者抛出异常,例如JSON
{
“errorMessage”: “CheckNoneAZNOperationIsExist”,
“errorCode”: 123
}
Finally, I have found solution. 最后,我找到了解决方案。
1) I added Error Code Variable (ex. globalError ) to all my boundary events 1)我向所有边界事件添加了错误代码变量(例如globalError )
2) After execution of process I check historic variable instance (Camunda Java API) 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) When error is occurred globalError is filled by Camunda Engine with "Error Name" 3)当发生错误globalError由Camunda引擎“错误名称”装
Camunda diagram example Camunda图示例
Result of code above 上面代码的结果
{
"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.