Skip to content

Commit

Permalink
An alternative approach
Browse files Browse the repository at this point in the history
`GenericEndpoint` now uses `CompletionException` as a wrapper instead of
`RuntimeException`, and wraps the cause of an
`InvocationTargetException` rather than the exception itself.
  • Loading branch information
pisv committed Feb 16, 2024
1 parent 4c49a57 commit 706d14b
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -64,13 +65,9 @@ protected void recursiveFindRpcMethods(Object current, Set<Class<?>> visited, Se
Object[] arguments = this.getArguments(method, arg);
return (CompletableFuture<Object>) method.invoke(current, arguments);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ResponseErrorException) {
ResponseErrorException ree = (ResponseErrorException) e.getTargetException();
throw ree;
}
throw new RuntimeException(e);
} catch ( IllegalAccessException e) {
throw new RuntimeException(e);
throw new CompletionException(e.getCause());
} catch (IllegalAccessException e) {
throw new CompletionException(e);
}
};
if (methodHandlers.put(methodInfo.name, handler) != null) {
Expand All @@ -86,13 +83,9 @@ protected void recursiveFindRpcMethods(Object current, Set<Class<?>> visited, Se
LOG.fine("A delegate object is null, jsonrpc methods of '" + method + "' are ignored");
}
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ResponseErrorException) {
ResponseErrorException ree = (ResponseErrorException) e.getTargetException();
throw ree;
}
throw new RuntimeException(e);
} catch ( IllegalAccessException e) {
throw new RuntimeException(e);
throw new CompletionException(e.getCause());
} catch (IllegalAccessException e) {
throw new CompletionException(e);
}
});
}
Expand Down

0 comments on commit 706d14b

Please sign in to comment.