109109import io .grpc .StatusRuntimeException ;
110110import java .util .UUID ;
111111import java .util .concurrent .CompletableFuture ;
112+ import java .util .concurrent .ExecutionException ;
112113import java .util .concurrent .ForkJoinPool ;
113114import java .util .concurrent .TimeUnit ;
114115import org .apache .thrift .TException ;
@@ -203,7 +204,7 @@ public RestartWorkflowExecutionResponse RestartWorkflowExecution(
203204 RestartWorkflowExecutionRequest restartRequest )
204205 throws BadRequestError , ServiceBusyError , DomainNotActiveError , LimitExceededError ,
205206 EntityNotExistsError , ClientVersionNotSupportedError , TException {
206- throw new IllegalArgumentException ("unimplemented" );
207+ throw new UnsupportedOperationException ("unimplemented" );
207208 }
208209
209210 @ Override
@@ -851,7 +852,7 @@ public void DeprecateDomain(
851852 public void RestartWorkflowExecution (
852853 RestartWorkflowExecutionRequest restartRequest , AsyncMethodCallback resultHandler )
853854 throws TException {
854- throw new IllegalArgumentException ("unimplemented" );
855+ throw new UnsupportedOperationException ("unimplemented" );
855856 }
856857
857858 @ Override
@@ -880,7 +881,7 @@ public void StartWorkflowExecutionAsync(
880881 resultHandler .onComplete (
881882 ResponseMapper .startWorkflowExecutionAsyncResponse (response ));
882883 } catch (Exception e ) {
883- resultHandler . onError ( e );
884+ handleAsyncException ( resultHandler , e );
884885 }
885886 },
886887 ForkJoinPool .commonPool ());
@@ -1003,7 +1004,7 @@ public void SignalWorkflowExecution(
10031004 com .uber .cadence .api .v1 .SignalWorkflowExecutionResponse response = resultFuture .get ();
10041005 resultHandler .onComplete (null );
10051006 } catch (Exception e ) {
1006- resultHandler . onError ( e );
1007+ handleAsyncException ( resultHandler , e );
10071008 }
10081009 },
10091010 ForkJoinPool .commonPool ());
@@ -1025,7 +1026,7 @@ public void SignalWithStartWorkflowExecutionAsync(
10251026 SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest ,
10261027 AsyncMethodCallback resultHandler )
10271028 throws TException {
1028- throw new IllegalArgumentException ("unimplemented" );
1029+ throw new UnsupportedOperationException ("unimplemented" );
10291030 }
10301031
10311032 @ Override
@@ -1199,7 +1200,7 @@ public void StartWorkflowExecutionWithTimeout(
11991200 com .uber .cadence .api .v1 .StartWorkflowExecutionResponse response = resultFuture .get ();
12001201 resultHandler .onComplete (ResponseMapper .startWorkflowExecutionResponse (response ));
12011202 } catch (Exception e ) {
1202- resultHandler . onError ( e );
1203+ handleAsyncException ( resultHandler , e );
12031204 }
12041205 },
12051206 ForkJoinPool .commonPool ());
@@ -1230,7 +1231,7 @@ public void StartWorkflowExecutionAsyncWithTimeout(
12301231 resultHandler .onComplete (
12311232 ResponseMapper .startWorkflowExecutionAsyncResponse (response ));
12321233 } catch (Exception e ) {
1233- resultHandler . onError ( e );
1234+ handleAsyncException ( resultHandler , e );
12341235 }
12351236 },
12361237 ForkJoinPool .commonPool ());
@@ -1276,7 +1277,7 @@ public void GetWorkflowExecutionHistoryWithTimeout(
12761277 resultHandler .onComplete (
12771278 ResponseMapper .getWorkflowExecutionHistoryResponse (response ));
12781279 } catch (Exception e ) {
1279- resultHandler . onError ( e );
1280+ handleAsyncException ( resultHandler , e );
12801281 }
12811282 },
12821283 ForkJoinPool .commonPool ());
@@ -1293,4 +1294,13 @@ public void SignalWorkflowExecutionWithTimeout(
12931294 throws TException {
12941295 throw new UnsupportedOperationException ("not implemented" );
12951296 }
1297+
1298+ private void handleAsyncException (AsyncMethodCallback callback , Exception exception ) {
1299+ if (exception instanceof ExecutionException
1300+ && exception .getCause () instanceof StatusRuntimeException ) {
1301+ callback .onError (ErrorMapper .Error (((StatusRuntimeException ) exception .getCause ())));
1302+ } else {
1303+ callback .onError (exception );
1304+ }
1305+ }
12961306}
0 commit comments