The error-message is reanderd instead of the text, in case of a 404
[demos/testing] / src / main / java / de / juplo / demo / HtmlController.java
index 5696718..d26c8c5 100644 (file)
@@ -5,6 +5,7 @@ import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
+import reactor.core.publisher.Mono;
 
 
 /**
@@ -26,7 +27,11 @@ public class HtmlController
   @GetMapping("/")
   public String fetch(Model model, @RequestParam String path)
   {
-    model.addAttribute("text", service.getRemoteText(path));
+    model.addAttribute(
+        "text",
+        service
+            .getRemoteText(path)
+            .onErrorResume(t -> Mono.just(t.getMessage())));
     return "home";
   }
 }