- Updated error response

This commit is contained in:
Max W. 2024-04-24 21:48:27 +02:00
parent b51250ffd3
commit c80403a4f6

View File

@ -1,6 +1,8 @@
package de.w665.sharepulse.rest; package de.w665.sharepulse.rest;
import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -10,10 +12,19 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class ErrorRestController implements ErrorController { public class ErrorRestController implements ErrorController {
@RequestMapping("/error") @RequestMapping("/error")
public String handleError() { public ResponseEntity<Object> handleError() {
return "<script>" + String script = "<script>" +
"console.log('Page not found. Redirecting to /home...');" + "console.log('Page not found. Redirecting to /home...');" +
"window.location.href = window.location.origin + '/home';" + "window.location.href = window.location.origin + '/home';" +
"</script>"; "</script>" +
"<h1>You've reached the default error page.</h1>" +
"<p>This could be caused by several reasons:</p>" +
"<ul>" +
"<li>The page you are looking for does not exist.</li>" +
"<li>The page you are looking for is not accessible.</li>" +
"<li>The page you are looking for is not available at the moment.</li>" +
"<li>The page you are looking for is not accessible without authentication.</li>" +
"</ul>";
return new ResponseEntity<>(script, HttpStatus.FOUND);
} }
} }