This Handler can be configured to handle certain HTTP response codes and map them to a Java Exception. It will get the exception message from the reason header.
In pom.xml
:
<dependency>
<groupId>org.microprofile-ext.restclient-ext</groupId>
<artifactId>configurable-errorresponse-handler</artifactId>
<version>XXXXX</version>
</dependency>
In your Microprofile rest client
@RegisterProvider(RuntimeResponseExceptionMapper.class)
Example:
@RequestScoped
@RegisterRestClient
@Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@RegisterProvider(RuntimeResponseExceptionMapper.class)
@Path("/api")
public interface MembershipProxy {
@GET @Path("/{id}") @Operation(hidden = true)
public Membership getMembership(@NotNull @PathParam(value = "id") int id);
}
Here some default mappings. You can add more mappings in your own config, or override these with your own config.(See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
- 401 Unauthorized (RFC 7235)
401/mp-restclient-ext/exception=javax.ws.rs.NotAuthorizedException
In your config (MicroProfile Config API) add your own mapping (examples above)
HTTP_Status_code/mp-restclient-ext/exception = Java_Exception_Name