From: Kai Moritz Date: Fri, 25 Mar 2022 14:20:00 +0000 (+0100) Subject: Verständliche Fehlermeldungen für DriverController X-Git-Tag: deserialization-synchroner-test~16^2~8 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=718a622ba2461dfceeab05b6b4f0f827b6e1fbfc;p=demos%2Fkafka%2Ftraining Verständliche Fehlermeldungen für DriverController --- diff --git a/src/main/java/de/juplo/kafka/DriverController.java b/src/main/java/de/juplo/kafka/DriverController.java index d8068e5..28aa69f 100644 --- a/src/main/java/de/juplo/kafka/DriverController.java +++ b/src/main/java/de/juplo/kafka/DriverController.java @@ -1,6 +1,7 @@ package de.juplo.kafka; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; @@ -25,4 +26,10 @@ public class DriverController { consumer.stop(); } + + @ExceptionHandler + public ErrorResponse illegalStateException(IllegalStateException e) + { + return new ErrorResponse(e.getMessage(), 400); + } } diff --git a/src/main/java/de/juplo/kafka/ErrorResponse.java b/src/main/java/de/juplo/kafka/ErrorResponse.java new file mode 100644 index 0000000..5ca206d --- /dev/null +++ b/src/main/java/de/juplo/kafka/ErrorResponse.java @@ -0,0 +1,11 @@ +package de.juplo.kafka; + +import lombok.Value; + + +@Value +public class ErrorResponse +{ + private final String error; + private final Integer status; +}