MP-RC provides support for mapping an invocation response into an exception via the org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper interface:
import javax.annotation.Priority;import javax.ws.rs.Priorities;import javax.ws.rs.core.MultivaluedMap;import javax.ws.rs.core.Response;import java.util.Optional;public interface ResponseExceptionMapper<T extends Throwable> { int DEFAULT_PRIORITY = Priorities.USER; T toThrowable(Response response); default boolean handles(int status, MultivaluedMap<String, Object> headers) { return status >= 400; } default int getPriority() { return Optional.ofNullable(getClass().getAnnotation(Priority.class)) .map(Priority::value) .orElse(DEFAULT_PRIORITY); }}
Consider the following ...