Verständliche Fehlermeldungen für DriverController
authorKai Moritz <kai@juplo.de>
Fri, 25 Mar 2022 14:20:00 +0000 (15:20 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 10 Apr 2022 17:44:14 +0000 (19:44 +0200)
src/main/java/de/juplo/kafka/DriverController.java
src/main/java/de/juplo/kafka/ErrorResponse.java [new file with mode: 0644]

index d8068e5..28aa69f 100644 (file)
@@ -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 (file)
index 0000000..5ca206d
--- /dev/null
@@ -0,0 +1,11 @@
+package de.juplo.kafka;
+
+import lombok.Value;
+
+
+@Value
+public class ErrorResponse
+{
+  private final String error;
+  private final Integer status;
+}