Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Portals committed Jul 30, 2024
1 parent d36cc42 commit 694ddb8
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
Expand All @@ -14,6 +16,8 @@
@Controller
public class GammaErrorController implements ErrorController {

private static final Logger LOGGER = LoggerFactory.getLogger(GammaErrorController.class);

@GetMapping("/error")
public ModelAndView handleRuntimeException(
@RequestHeader(value = "HX-Request", required = false) boolean htmxRequest,
Expand All @@ -24,6 +28,12 @@ public ModelAndView handleRuntimeException(
int statusCode = statusCodeString == null ? 500 : Integer.parseInt(statusCodeString.toString());

Exception exception = (Exception) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
if (exception == null) {
LOGGER.error("error, but no exception...");
} else {
LOGGER.error("Caught error, rendering error page...", exception);
}

String page = "pages/error";

if (HttpStatus.valueOf(statusCode) == HttpStatus.NOT_FOUND) {
Expand Down

0 comments on commit 694ddb8

Please sign in to comment.