From 25ac228e059eb83312b9b6daa75f6962161811db Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 25 Mar 2022 15:20:00 +0100 Subject: [PATCH] =?utf8?q?Verst=C3=A4ndliche=20Fehlermeldungen=20f=C3=BCr?= =?utf8?q?=20DriverController?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/de/juplo/kafka/DriverController.java | 7 +++++++ src/main/java/de/juplo/kafka/ErrorResponse.java | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/java/de/juplo/kafka/ErrorResponse.java 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; +} -- 2.20.1