Skip to content

Commit

Permalink
Provide context for Reactive Rest Client exceptions
Browse files Browse the repository at this point in the history
We now add the exact method that caused the exception
in order to make it easier for users to identity where
the exception is coming from

Fixes: quarkusio#22090
  • Loading branch information
geoand committed Dec 10, 2021
1 parent 8bc2149 commit 0b46531
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URI;
Expand Down Expand Up @@ -46,6 +47,8 @@
*/
public class RestClientRequestContext extends AbstractResteasyReactiveContext<RestClientRequestContext, ClientRestHandler> {

private static final String MP_INVOKED_METHOD_PROP = "org.eclipse.microprofile.rest.client.invokedMethod";

private final HttpClient httpClient;
// Changeable by the request filter
String httpMethod;
Expand Down Expand Up @@ -140,8 +143,16 @@ public void abort() {
protected Throwable unwrapException(Throwable t) {
var res = super.unwrapException(t);
if (res instanceof WebApplicationException) {
WebApplicationException webApplicationException = (WebApplicationException) res;
return new ClientWebApplicationException(webApplicationException.getMessage(), webApplicationException,
var webApplicationException = (WebApplicationException) res;
var message = webApplicationException.getMessage();
var invokedMethodObject = properties.get(MP_INVOKED_METHOD_PROP);
if ((invokedMethodObject instanceof Method)) {
var invokedMethod = (Method) invokedMethodObject;
message = "Received: '" + message + "' when invoking: Rest Client method: '"
+ invokedMethod.getDeclaringClass().getName() + "#"
+ invokedMethod.getName() + "'";
}
return new ClientWebApplicationException(message, webApplicationException,
webApplicationException.getResponse());
}
return res;
Expand Down

0 comments on commit 0b46531

Please sign in to comment.