Skip to content

Commit

Permalink
Merge pull request #1679 from jmartisk/issue-1668
Browse files Browse the repository at this point in the history
Avoid wrapping runtime exceptions between interceptors in some cases.…
  • Loading branch information
mkouba authored Mar 25, 2019
2 parents 26e4bef + 2fbdb45 commit db6a012
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ public static Object invokeMethod(Class<?> clazz, String name, Class<?>[] paramT
method.setAccessible(true);
}
return method.invoke(instance, args);
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
| InvocationTargetException e) {
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new RuntimeException("Cannot invoke method: " + clazz.getName() + "#" + name + " on " + instance, e);
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Cannot invoke method: " + clazz.getName() + "#" + name + " on " + instance, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.Path;

import org.eclipse.microprofile.metrics.Histogram;
Expand Down Expand Up @@ -84,4 +85,11 @@ public String counterWithTags() {
return "TEST";
}

@GET
@Path("/counter-throwing-not-found-exception")
@Counted(monotonic = true, name = "counter_404")
public String counterWithTagsThrowingNotFound() {
throw new NotFoundException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ public void testVendorMetrics() {
.body(containsString("vendor:memory_max_non_heap_bytes "));
}

/**
* A REST method with metrics is throwing a NotFoundException, so the client should receive 404.
*/
@Test
public void testEndpointWithMetricsThrowingException() {
RestAssured.when().get("/metricsresource/counter-throwing-not-found-exception").then()
.statusCode(404);
}

private void assertMetricExactValue(String name, String val) {
RestAssured.when().get("/metrics").then()
.body(containsString(name + " " + val));
Expand Down

0 comments on commit db6a012

Please sign in to comment.