Skip to content

Commit

Permalink
fix: exception mapper (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored May 29, 2024
1 parent e468457 commit ec54a5c
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.tkit.onecx.permission.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 @@ -18,6 +20,7 @@
import gen.org.tkit.onecx.permission.bff.rs.internal.model.ProblemDetailInvalidParamDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.ProblemDetailParamDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.ProblemDetailResponseDTO;
import gen.org.tkit.onecx.permission.model.ProblemDetailResponse;

@Mapper(uses = { OffsetDateTimeMapper.class })
public interface ExceptionMapper {
Expand Down Expand Up @@ -63,7 +66,17 @@ default Response clientException(ClientWebApplicationException ex) {
if (ex.getResponse().getStatus() == 500) {
return Response.status(400).build();
} else {
return Response.status(ex.getResponse().getStatus()).build();
if (ex.getResponse().getMediaType() != null
&& ex.getResponse().getMediaType().toString().contains(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);
}

0 comments on commit ec54a5c

Please sign in to comment.