Skip to content

Commit

Permalink
fix: docs (#15)
Browse files Browse the repository at this point in the history
* fix: docs

* feat: improved exception handler
  • Loading branch information
JordenReuter authored Apr 23, 2024
1 parent c32d7fe commit 292b97e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: onecx-welcome
title: Welcome Bff
title: Welcome Management
version: latest
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +118,7 @@ public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationExce
}

@ServerExceptionMapper
public Response restException(WebApplicationException ex) {
return Response.status(ex.getResponse().getStatus()).build();
public Response restException(ClientWebApplicationException ex) {
return exceptionMapper.clientException(ex);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -27,6 +31,24 @@ default RestResponse<ProblemDetailResponseDTO> 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)
Expand Down

0 comments on commit 292b97e

Please sign in to comment.