Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support handle of exception from onResponse or onError #4401

Merged
merged 4 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ public Object recreate() throws Throwable {

@Override
public Result whenCompleteWithContext(BiConsumer<Result, Throwable> fn) {
this.whenComplete((v, t) -> {
CompletableFuture<Result> future = this.whenComplete((v, t) -> {
beforeContext.accept(v, t);
fn.accept(v, t);
afterContext.accept(v, t);
});
// You may need to return a new Result instance representing the next async stage,
// like thenApply will return a new CompletableFuture.
return this;

AsyncRpcResult nextStage = new AsyncRpcResult(this);
nextStage.subscribeTo(future);
return nextStage;
}

public void subscribeTo(CompletableFuture<?> future) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,33 +156,24 @@ public CallbackRegistrationInvoker(Invoker<T> filterInvoker, List<Filter> filter
public Result invoke(Invocation invocation) throws RpcException {
Result asyncResult = filterInvoker.invoke(invocation);

asyncResult.whenCompleteWithContext((r, t) -> {
asyncResult = asyncResult.whenCompleteWithContext((r, t) -> {
for (int i = filters.size() - 1; i >= 0; i--) {
Filter filter = filters.get(i);
// onResponse callback
if (filter instanceof ListenableFilter) {
Filter.Listener listener = ((ListenableFilter) filter).listener();
if (listener != null) {
try {
if (t == null) {
listener.onResponse(r, filterInvoker, invocation);
} else {
listener.onError(t, filterInvoker, invocation);
}
} catch (Throwable filterError) {
t = filterError;
if (t == null) {
listener.onResponse(r, filterInvoker, invocation);
} else {
listener.onError(t, filterInvoker, invocation);
}
}
} else {
try {
filter.onResponse(r, filterInvoker, invocation);
} catch (Throwable filterError) {
t = filterError;
}
filter.onResponse(r, filterInvoker, invocation);
}
}
});

return asyncResult;
}

Expand Down