Skip to content

Commit

Permalink
Vertx: avoid doulbe wrapping exception handler (#3848)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Aug 17, 2021
1 parent 430f1cb commit c54d192
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static void wrapExceptionHandler(
if (handler != null) {
ContextStore<HttpClientRequest, Contexts> contextStore =
InstrumentationContext.get(HttpClientRequest.class, Contexts.class);
handler = new ExceptionHandlerWrapper(tracer(), request, contextStore, handler);
handler = ExceptionHandlerWrapper.wrap(tracer(), request, contextStore, handler);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static void wrapExceptionHandler(
if (handler != null) {
ContextStore<HttpClientRequest, Contexts> contextStore =
InstrumentationContext.get(HttpClientRequest.class, Contexts.class);
handler = new ExceptionHandlerWrapper(tracer(), request, contextStore, handler);
handler = ExceptionHandlerWrapper.wrap(tracer(), request, contextStore, handler);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExceptionHandlerWrapper implements Handler<Throwable> {
private final ContextStore<HttpClientRequest, Contexts> contextStore;
private final Handler<Throwable> handler;

public ExceptionHandlerWrapper(
private ExceptionHandlerWrapper(
AbstractVertxClientTracer tracer,
HttpClientRequest request,
ContextStore<HttpClientRequest, Contexts> contextStore,
Expand All @@ -27,6 +27,18 @@ public ExceptionHandlerWrapper(
this.handler = handler;
}

public static Handler<Throwable> wrap(
AbstractVertxClientTracer tracer,
HttpClientRequest request,
ContextStore<HttpClientRequest, Contexts> contextStore,
Handler<Throwable> handler) {
if (handler instanceof ExceptionHandlerWrapper) {
return handler;
}

return new ExceptionHandlerWrapper(tracer, request, contextStore, handler);
}

@Override
public void handle(Throwable throwable) {
Contexts contexts = contextStore.get(request);
Expand Down

0 comments on commit c54d192

Please sign in to comment.