From 292b97e3cd6ed1345bc5d3f4d723993ff33f7ce9 Mon Sep 17 00:00:00 2001 From: JordenReuter <149687553+JordenReuter@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:25:54 +0200 Subject: [PATCH] fix: docs (#15) * fix: docs * feat: improved exception handler --- docs/antora.yml | 2 +- .../rs/controllers/ImagesRestController.java | 6 ++--- .../bff/rs/mappers/ExceptionMapper.java | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/antora.yml b/docs/antora.yml index 440d2c5..ba7aa3e 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -1,3 +1,3 @@ name: onecx-welcome -title: Welcome Bff +title: Welcome Management version: latest \ No newline at end of file diff --git a/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java b/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java index f515228..cf64473 100644 --- a/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java +++ b/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java @@ -7,10 +7,10 @@ import jakarta.inject.Inject; import jakarta.transaction.Transactional; import jakarta.validation.ConstraintViolationException; -import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Response; import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.jboss.resteasy.reactive.ClientWebApplicationException; import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.server.ServerExceptionMapper; import org.tkit.onecx.welcome.bff.rs.mappers.ExceptionMapper; @@ -118,7 +118,7 @@ public RestResponse constraint(ConstraintViolationExce } @ServerExceptionMapper - public Response restException(WebApplicationException ex) { - return Response.status(ex.getResponse().getStatus()).build(); + public Response restException(ClientWebApplicationException ex) { + return exceptionMapper.clientException(ex); } } diff --git a/src/main/java/org/tkit/onecx/welcome/bff/rs/mappers/ExceptionMapper.java b/src/main/java/org/tkit/onecx/welcome/bff/rs/mappers/ExceptionMapper.java index 9cd6ffb..9d6fc3a 100644 --- a/src/main/java/org/tkit/onecx/welcome/bff/rs/mappers/ExceptionMapper.java +++ b/src/main/java/org/tkit/onecx/welcome/bff/rs/mappers/ExceptionMapper.java @@ -1,5 +1,7 @@ package org.tkit.onecx.welcome.bff.rs.mappers; +import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; + import java.util.List; import java.util.Map; import java.util.Set; @@ -9,6 +11,7 @@ import jakarta.validation.Path; import jakarta.ws.rs.core.Response; +import org.jboss.resteasy.reactive.ClientWebApplicationException; import org.jboss.resteasy.reactive.RestResponse; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -17,6 +20,7 @@ import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ProblemDetailInvalidParamDTO; import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ProblemDetailParamDTO; import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ProblemDetailResponseDTO; +import gen.org.tkit.onecx.welcome.client.model.ProblemDetailResponse; @Mapper(uses = { OffsetDateTimeMapper.class }) public interface ExceptionMapper { @@ -27,6 +31,24 @@ default RestResponse constraint(ConstraintViolationExc return RestResponse.status(Response.Status.BAD_REQUEST, dto); } + default Response clientException(ClientWebApplicationException ex) { + if (ex.getResponse().getStatus() == 500) { + return Response.status(400).build(); + } else { + if (ex.getResponse().getMediaType() != null + && ex.getResponse().getMediaType().toString().equals(APPLICATION_JSON)) { + return Response.status(ex.getResponse().getStatus()) + .entity(map(ex.getResponse().readEntity(ProblemDetailResponse.class))).build(); + } else { + return Response.status(ex.getResponse().getStatus()).build(); + } + } + } + + @Mapping(target = "removeParamsItem", ignore = true) + @Mapping(target = "removeInvalidParamsItem", ignore = true) + ProblemDetailResponseDTO map(ProblemDetailResponse problemDetailResponse); + @Mapping(target = "removeParamsItem", ignore = true) @Mapping(target = "params", ignore = true) @Mapping(target = "invalidParams", ignore = true)