如何通过我的API处理医院异常? [英] How Do I Handle Hospital Exceptions From My API?
问题描述
出于业务原因,我在状态栏上添加了唯一约束.
I have added a unique constraint on a column in my state for business reasons.
当我尝试对我的REST API进行多次调用而打破了此限制时,流程被送往医院,并且该API从未返回.
When I tried to make multiple calls to my REST API that would break this constraint the flow went to the Hospital and the API never returned.
[INFO ] 2020-11-13T03:14:02,254Z [Node thread-1] statemachine.StaffedFlowHospital. - Flow [13e5039f-0af6-4225-9d93-964897e406a9] admitted to hospital in state StateMachineState
net.corda.node.services.statemachine.StateTransitionException: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Unique index or primary key violation:
[INFO ] 2020-11-13T03:14:02,575Z [Node thread-1] statemachine.StaffedFlowHospital. - Flow error kept for overnight observation by [net.corda.node.services.statemachine.StaffedFlowHospital$TransitionErrorGeneralPractitioner@73c67012]
[WARN ] 2020-11-13T03:14:09,208Z [FlowHospitalJobTimer] statemachine.StaffedFlowHospital. - There are 1 flows kept for overnight observation. Affected flow ids: 13e5039f-0af6-4225-9d93-964897e406a9
作为旁注:现在每分钟都会将最后一个WARN消息打印到日志中!
As a side note: that last WARN message is now printed to the log every minute!
我的API调用如下:
FlowHandle<SignedTransaction> flowHandle = proxy.startFlowDynamic(TestFlow.class,
request.getId(),
request.getMake(),
request.getModel()
);
try {
SignedTransaction signedTransaction = flowHandle.getReturnValue().toCompletableFuture().get();
由于流程进入医院,因此永远不会完成,也永远不会出错.
Since the flow goes to the hospital it never completes and also never errors.
我应该如何处理?
此外,如果节点根本不向我返回任何东西,我应该如何知道流程去了医院,以及什么错误导致流程去了医院?
Also, if the node never returns anything at all to me, how am I supposed to know that the flow went to the hospital and what the error was that caused it to go to the hospital?
推荐答案
- 从Corda 4.6开始,您可以为流分配一个唯一的ID,以使您可以将客户端重新连接到该流(即使完成后),以防连接因某种原因而中断.在此处中阅读.
- 我认为您需要为REST API创建一个全局异常处理程序,并添加一种方法来处理
ConstraintViolationException
;它会捕获该异常并对其进行处理(由您决定,您可以返回特定的HTTP错误代码和特定的消息).在此处阅读. - Starting Corda 4.6 you can assign a unique ID to your flow, allowing you to re-attach your client to that flow (even after it completed) in case the connection breaks at some point for any reason. Read about it here.
- I think you need to create a global exception handler for your REST APIs, and add a method to handle
ConstraintViolationException
; it will catch that exception and do something with it (it's up to you, you can return a certain HTTP error code and a specific message). Read about it here.
这篇关于如何通过我的API处理医院异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!