All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.views.ViewRenderExceptionMapper Maven / Gradle / Ivy

There is a newer version: 5.0.0-alpha.5
Show newest version
package io.dropwizard.views;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.glassfish.jersey.spi.ExtendedExceptionMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * An {@link ExtendedExceptionMapper} that returns a 500 error response with a generic
 * HTML error page when a {@link ViewRenderException} is the cause.
 *
 * @since 1.1.0
 */
@Provider
public class ViewRenderExceptionMapper implements ExtendedExceptionMapper {

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

    /**
     * The generic HTML error page template.
     */
    public static final String TEMPLATE_ERROR_MSG =
            "" +
                "Template Error" +
                "

Template Error

Something went wrong rendering the page

" + ""; @Override public Response toResponse(WebApplicationException exception) { LOGGER.error("Template Error", exception); return Response.serverError() .type(MediaType.TEXT_HTML_TYPE) .entity(TEMPLATE_ERROR_MSG) .build(); } @Override public boolean isMappable(WebApplicationException e) { return ExceptionUtils.indexOfThrowable(e, ViewRenderException.class) != -1; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy