Verified correct behavior of RestController for 404
[demos/testing] / src / main / java / de / juplo / demo / RestController.java
index f6cddca..5d1d8f6 100644 (file)
@@ -1,11 +1,13 @@
 package de.juplo.demo;
 
 
+import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.reactive.function.client.WebClientResponseException;
 import org.springframework.web.reactive.function.client.WebClientResponseException.NotFound;
+import org.springframework.web.server.ResponseStatusException;
 import reactor.core.publisher.Mono;
 
 
@@ -34,25 +36,21 @@ public class RestController
             .onErrorResume(t ->
             {
               if(t.getClass().equals(NotFound.class))
-                return Mono.error(t);
+                return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Cause: " + t.getMessage(), t));
               if(!(t instanceof WebClientResponseException))
                 return
                     Mono.error(
-                        WebClientResponseException.create(
-                            500,
-                            "Internal Server Error - Cause: " + t.getMessage(),
-                            null,
-                            null,
-                            null));
+                        new ResponseStatusException(
+                            HttpStatus.INTERNAL_SERVER_ERROR,
+                            "Cause: " + t.getMessage(),
+                            t));
 
               return
                   Mono.error(
-                      WebClientResponseException.create(
-                          503,
-                          "Service Unavailable - Cause: " + t.getMessage(),
-                          null,
-                          null,
-                          null));
+                      new ResponseStatusException(
+                          HttpStatus.SERVICE_UNAVAILABLE,
+                          "Cause: " + t.getMessage(),
+                          t));
             });
   }
 }