Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Override 500 Error from Dispatcher Cloud Service


Level 2

Hey guys,


I have written an AbstractServlet implementation to handle a variety of different servlet calls (doPost method below). I intend for this servlet to return an error message -- specifically the failureMessage property -- when a 500 is thrown, but instead I am getting the default 500 page (image attached) as the response... On my local dispatcher instance, I was able to bypass this page by setting the status to 499, but said approach is not working in the hosted staging environment (maybe something to do w/ local vs. cloud service setup). Does anybody have any experience writing a similar implementation / dealing with a similar issue? Thanks for any and all insight



    protected void doPost(@NotNull SlingHttpServletRequest request, @notnull SlingHttpServletResponse response) throws IOException {
        T requestData = getRequestData(request);
        if (requestData == null || !isValidRequest(requestData)) {
            response.getWriter().write(new ObjectMapper().writeValueAsString(new ServletError("Expected parameter is missing")));
        boolean result = performAction(requestData);
        if (result) {
            response.getWriter().write(new ObjectMapper().writeValueAsString(new ServletSuccess(getSuccessMessage())));
        } else {
            response.getWriter().write(new ObjectMapper().writeValueAsString(new ServletSuccess(getFailureMessage())));



1 Reply