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>
Fri, 25 Mar 2022 14:20:00 +0000 (15:20 +0100)
src/main/java/de/juplo/kafka/DriverController.java
src/main/java/de/juplo/kafka/ErrorResponse.java [new file with mode: 0644]

index f8a287d..b3af107 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
   {
     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 (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;
+}