Skip to content

Commit f7fd74f

Browse files
authored
handle proto NOT_FOUND status exception (#687)
1 parent 3bd2e02 commit f7fd74f

File tree

1 file changed

+58
-24
lines changed

1 file changed

+58
-24
lines changed

src/main/java/com/uber/cadence/internal/compatibility/Thrift2ProtoAdapter.java

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,29 @@ private StartWorkflowExecutionResponse startWorkflowExecution(
187187
.startWorkflowExecution(RequestMapper.startWorkflowExecutionRequest(startRequest));
188188
return ResponseMapper.startWorkflowExecutionResponse(response);
189189
} catch (StatusRuntimeException e) {
190-
// TODO handle all errors depending on status
191-
switch (e.getStatus().getCode()) {
192-
case ALREADY_EXISTS:
190+
convertAndThrowStatusException(e);
191+
throw e;
192+
}
193+
}
194+
195+
private void convertAndThrowStatusException(StatusRuntimeException e)
196+
throws BadRequestError, WorkflowExecutionAlreadyStartedError, ServiceBusyError,
197+
DomainNotActiveError, LimitExceededError, EntityNotExistsError,
198+
ClientVersionNotSupportedError {
199+
// TODO handle all errors depending on status
200+
switch (e.getStatus().getCode()) {
201+
case ALREADY_EXISTS:
202+
{
193203
WorkflowExecutionAlreadyStartedError ex = new WorkflowExecutionAlreadyStartedError();
194204
ex.setMessage(e.getMessage());
195205
throw ex;
196-
default:
197-
throw e;
198-
}
206+
}
207+
case NOT_FOUND:
208+
{
209+
throw new EntityNotExistsError(e.getMessage());
210+
}
211+
default:
212+
throw e;
199213
}
200214
}
201215

@@ -216,11 +230,16 @@ public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistory(
216230
public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskRequest pollRequest)
217231
throws BadRequestError, ServiceBusyError, LimitExceededError, EntityNotExistsError,
218232
DomainNotActiveError, ClientVersionNotSupportedError, TException {
219-
com.uber.cadence.api.v1.PollForDecisionTaskResponse response =
220-
grpcServiceStubs
221-
.workerBlockingStub()
222-
.pollForDecisionTask(RequestMapper.pollForDecisionTaskRequest(pollRequest));
223-
return ResponseMapper.pollForDecisionTaskResponse(response);
233+
try {
234+
com.uber.cadence.api.v1.PollForDecisionTaskResponse response =
235+
grpcServiceStubs
236+
.workerBlockingStub()
237+
.pollForDecisionTask(RequestMapper.pollForDecisionTaskRequest(pollRequest));
238+
return ResponseMapper.pollForDecisionTaskResponse(response);
239+
} catch (StatusRuntimeException e) {
240+
convertAndThrowStatusException(e);
241+
throw e;
242+
}
224243
}
225244

226245
@Override
@@ -229,12 +248,17 @@ public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(
229248
throws BadRequestError, EntityNotExistsError, DomainNotActiveError, LimitExceededError,
230249
ServiceBusyError, ClientVersionNotSupportedError, WorkflowExecutionAlreadyCompletedError,
231250
TException {
232-
com.uber.cadence.api.v1.RespondDecisionTaskCompletedResponse response =
233-
grpcServiceStubs
234-
.workerBlockingStub()
235-
.respondDecisionTaskCompleted(
236-
RequestMapper.respondDecisionTaskCompletedRequest(completeRequest));
237-
return ResponseMapper.respondDecisionTaskCompletedResponse(response);
251+
try {
252+
com.uber.cadence.api.v1.RespondDecisionTaskCompletedResponse response =
253+
grpcServiceStubs
254+
.workerBlockingStub()
255+
.respondDecisionTaskCompleted(
256+
RequestMapper.respondDecisionTaskCompletedRequest(completeRequest));
257+
return ResponseMapper.respondDecisionTaskCompletedResponse(response);
258+
} catch (StatusRuntimeException e) {
259+
convertAndThrowStatusException(e);
260+
throw e;
261+
}
238262
}
239263

240264
@Override
@@ -359,10 +383,15 @@ public void RequestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest
359383
ServiceBusyError, DomainNotActiveError, LimitExceededError,
360384
ClientVersionNotSupportedError, WorkflowExecutionAlreadyCompletedError, TException {
361385
cancelRequest.setRequestId(UUID.randomUUID().toString());
362-
grpcServiceStubs
363-
.workflowBlockingStub()
364-
.requestCancelWorkflowExecution(
365-
RequestMapper.requestCancelWorkflowExecutionRequest(cancelRequest));
386+
try {
387+
grpcServiceStubs
388+
.workflowBlockingStub()
389+
.requestCancelWorkflowExecution(
390+
RequestMapper.requestCancelWorkflowExecutionRequest(cancelRequest));
391+
} catch (StatusRuntimeException e) {
392+
convertAndThrowStatusException(e);
393+
throw e;
394+
}
366395
}
367396

368397
@Override
@@ -371,9 +400,14 @@ public void SignalWorkflowExecution(SignalWorkflowExecutionRequest signalRequest
371400
LimitExceededError, ClientVersionNotSupportedError,
372401
WorkflowExecutionAlreadyCompletedError, TException {
373402
signalRequest.setRequestId(UUID.randomUUID().toString());
374-
grpcServiceStubs
375-
.workflowBlockingStub()
376-
.signalWorkflowExecution(RequestMapper.signalWorkflowExecutionRequest(signalRequest));
403+
try {
404+
grpcServiceStubs
405+
.workflowBlockingStub()
406+
.signalWorkflowExecution(RequestMapper.signalWorkflowExecutionRequest(signalRequest));
407+
} catch (StatusRuntimeException e) {
408+
convertAndThrowStatusException(e);
409+
throw e;
410+
}
377411
}
378412

379413
@Override

0 commit comments

Comments
 (0)