diff --git a/iris-client-bff/src/main/java/iris/client_bff/config/DataSubmissionConfig.java b/iris-client-bff/src/main/java/iris/client_bff/config/DataSubmissionConfig.java index 59917a8c0..f2f73d1c1 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/config/DataSubmissionConfig.java +++ b/iris-client-bff/src/main/java/iris/client_bff/config/DataSubmissionConfig.java @@ -1,5 +1,7 @@ package iris.client_bff.config; +import static com.googlecode.jsonrpc4j.ErrorResolver.JsonError.*; + import iris.client_bff.cases.eps.CaseDataController; import iris.client_bff.core.alert.AlertService; import iris.client_bff.events.eps.EventDataController; @@ -11,6 +13,11 @@ import java.lang.reflect.Method; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; + +import javax.validation.ConstraintViolationException; import org.springframework.context.NoSuchMessageException; import org.springframework.context.annotation.Bean; @@ -24,6 +31,7 @@ import com.googlecode.jsonrpc4j.AnnotationsErrorResolver; import com.googlecode.jsonrpc4j.DefaultErrorResolver; import com.googlecode.jsonrpc4j.ErrorData; +import com.googlecode.jsonrpc4j.ErrorResolver; import com.googlecode.jsonrpc4j.JsonRpcInterceptor; import com.googlecode.jsonrpc4j.MultipleErrorResolver; import com.googlecode.jsonrpc4j.ProxyUtil; @@ -35,9 +43,12 @@ public class DataSubmissionConfig { public static final String DATA_SUBMISSION_ENDPOINT = "/data-submission-rpc"; - public static final String DATA_SUBMISSION_ENDPOINT_WITH_SLASH = "/data-submission-rpc/"; + private final Map, Integer> exception2CodeMap = Map.of( + ConstraintViolationException.class, INVALID_REQUEST.code, + IllegalArgumentException.class, INVALID_REQUEST.code); + private final MessageSourceAccessor messages; private final UserService userService; private final AlertService alertService; @@ -94,7 +105,7 @@ private JsonServiceExporter createCompositeJsonServiceExporter() { private final class MessageResolvingErrorResolver extends MultipleErrorResolver { private MessageResolvingErrorResolver() { - super(AnnotationsErrorResolver.INSTANCE, DefaultErrorResolver.INSTANCE); + super(AnnotationsErrorResolver.INSTANCE, new IrisErrorResolver(), DefaultErrorResolver.INSTANCE); } @Override @@ -119,6 +130,25 @@ public JsonError resolveError(Throwable t, Method method, List argumen } } + private class IrisErrorResolver implements ErrorResolver { + + @Override + public JsonError resolveError(Throwable t, Method method, List arguments) { + + return determineCode(t) + .map(code -> new JsonError(code, t.getMessage(), new ErrorData(t.getClass().getName(), t.getMessage()))) + .orElse(null); + } + + private Optional determineCode(Throwable t) { + + return exception2CodeMap.entrySet().stream() + .filter(it -> it.getKey().isAssignableFrom(t.getClass())) + .map(Entry::getValue) + .findAny(); + } + } + /** * @author Jens Kutzsche */ diff --git a/iris-client-bff/src/main/java/iris/client_bff/events/eps/EventDataController.java b/iris-client-bff/src/main/java/iris/client_bff/events/eps/EventDataController.java index 6b7466118..a361a8782 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/events/eps/EventDataController.java +++ b/iris-client-bff/src/main/java/iris/client_bff/events/eps/EventDataController.java @@ -17,7 +17,7 @@ public interface EventDataController { @JsonRpcErrors({ - @JsonRpcError(exception = ResponseStatusException.class, code = -32600) + @JsonRpcError(exception = ResponseStatusException.class, code = -32602) }) String submitGuestList( @JsonRpcParam(value = "_client") @Valid JsonRpcClientDto client, diff --git a/iris-client-bff/src/main/java/iris/client_bff/vaccination_info/eps/VaccinationInfoController.java b/iris-client-bff/src/main/java/iris/client_bff/vaccination_info/eps/VaccinationInfoController.java index fef5e3630..c87d7e85b 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/vaccination_info/eps/VaccinationInfoController.java +++ b/iris-client-bff/src/main/java/iris/client_bff/vaccination_info/eps/VaccinationInfoController.java @@ -6,6 +6,7 @@ import iris.client_bff.core.validation.Base64; import iris.client_bff.core.validation.NoSignOfAttack; import iris.client_bff.core.validation.PhoneNumber; +import iris.client_bff.vaccination_info.VaccinationInfoAnnouncementException; import iris.client_bff.vaccination_info.VaccinationStatus; import iris.client_bff.vaccination_info.VaccinationType; @@ -14,7 +15,6 @@ import java.util.UUID; import javax.annotation.Nullable; -import javax.validation.ConstraintViolationException; import javax.validation.Valid; import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; @@ -35,16 +35,12 @@ public interface VaccinationInfoController { @JsonRpcErrors({ - @JsonRpcError(exception = ConstraintViolationException.class, code = -32600), - @JsonRpcError(exception = InvalidPublicKeyException.class, code = -32600) + @JsonRpcError(exception = InvalidPublicKeyException.class, code = -32600), + @JsonRpcError(exception = VaccinationInfoAnnouncementException.class, code = -32603) }) AnnouncementResultDto announceVaccinationInfoList( @JsonRpcParam(value = "announcementData") @Valid AnnouncementDataDto announcementData); - @JsonRpcErrors({ - @JsonRpcError(exception = ConstraintViolationException.class, code = -32600), - @JsonRpcError(exception = IllegalArgumentException.class, code = -32600) - }) String submitVaccinationInfoList( @JsonRpcParam(value = "dataAuthorizationToken") @NotNull UUID dataAuthorizationToken, @JsonRpcParam(value = "facility") @Valid Facility facility,