openanalytics / containerproxy

Manage HTTP proxy routes into Docker containers
Apache License 2.0
45 stars 66 forks source link

Extracting Status Codes from Requests #78

Closed anisdismail closed 5 months ago

anisdismail commented 1 year ago

I would like to extract the status codes to be able to create custom error pages for different errors. As implemented here:

Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
            int statusCode = Integer.parseInt(status.toString());
            if (statusCode == HttpStatus.NOT_FOUND.value()) {
                shortError = "Not found";
                description = "The requested page was not found";
            } else if (statusCode == HttpStatus.FORBIDDEN.value()) {
                shortError = "Forbidden";
                description = "You do not have access to this page";
            } else if (statusCode == HttpStatus.METHOD_NOT_ALLOWED.value()) {
                shortError = "Method not allowed";
            }
        }
prepareMap(map);
map.put("mainPage", ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString());
map.put("shortError", shortError);
map.put("description", description);

Inside the ErrorController, the status code is not shared in the Thymeleaf mapper and instead a short error text is shared. As far as I have looked, there doesn't seem to be any way currently to extract the status codes and pass them through Thymeleaf. Any suggestions would be very appreciated!

LEDfan commented 1 year ago

Hi There is currently no way to get the status code in the thymeleaf template. I logged an internal ticket to make this object available in the template.

LEDfan commented 5 months ago

Hi, this is now part of the ShinyProxy 3.1.0 we released today, see https://github.com/openanalytics/shinyproxy-config-examples/tree/master/04-custom-html-template#request-and-response-variables . Thank you for this suggestion!