From: Kai Moritz Date: Fri, 25 Mar 2022 14:20:00 +0000 (+0100) Subject: Verständliche Fehlermeldungen für DriverController X-Git-Tag: acks-KAPUTT-DEPRECATED~11 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=25ac228e059eb83312b9b6daa75f6962161811db;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 f8a287d..b3af107 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 { producer.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; +}