Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2882

MicroProfile Client ignores NULL ResponseExceptionMapper

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 3.14.0.Final
    • None

      Default behavior:

      1. Building an MP REST client
      2. Request a resource that returns e.g. HTTP 503 status code (MP-Health endpoint which is down)
      3. A WebApplicationException is thrown

      Alternate behavior:

      1. Building an MP REST client
      2. Register ResponseExceptionMapper which handles HTTP 503, but returns NULL for org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper#toThrowable
      3. Request a resource which returns HTTP 503
      4. A java.lang.reflect.UndeclaredThrowableException is thrown

      Expected:

      If I interpret it correctly, there should be no exception at all, according to https://github.com/eclipse/microprofile-rest-client/blob/1.4.1/spec/src/main/asciidoc/providers.asciidoc#how-to-implement-responseexceptionmapper.

      This method may return null if no throwable should be raised.

      Eventual source of evil:

      org.jboss.resteasy.microprofile.client.ExceptionMapping.HandlerException

      Some code:

      public class Ignore503ExceptionMapper implements ResponseExceptionMapper<WebApplicationException> {
      
          @Override
          public WebApplicationException toThrowable(Response response) {
              return null;
          }
      
          @Override
          public boolean handles(int status, MultivaluedMap<String, Object> headers) {
              // as per MP-Health specification
              return 503 == status;
          }
      }
      
      public interface HealthService extends Closeable {
      @GET
      @Produces({ MediaType.APPLICATION_JSON})
      @Path("/health")
      HealthCheckData getHealthData();
      }
      
      RestClientBuilder.newBuilder()
      .register(new Ignore503ExceptionMapper())
      .build(HealthService.class)
      .getHealthData();
      

       

              rsearls r searls
              svenhaag Sven Haag (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: