001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.http.commons.exceptionhandlers;
007
008import static javax.ws.rs.core.Response.Status.BAD_GATEWAY;
009import static javax.ws.rs.core.Response.status;
010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
011import static org.slf4j.LoggerFactory.getLogger;
012
013
014import javax.ws.rs.core.Response;
015import javax.ws.rs.ext.ExceptionMapper;
016import javax.ws.rs.ext.Provider;
017
018import org.fcrepo.kernel.api.exception.ExternalContentAccessException;
019
020import org.slf4j.Logger;
021
022/**
023 * ExternalContentException mapper
024 *
025 * @author whikloj
026 * @since 2018-07-11
027 */
028@Provider
029public class ExternalContentAccessExceptionMapper
030    implements ExceptionMapper<ExternalContentAccessException>, ExceptionDebugLogging {
031
032    private static final Logger LOGGER = getLogger(ExternalContentAccessExceptionMapper.class);
033
034    @Override
035    public Response toResponse(final ExternalContentAccessException exception) {
036        LOGGER.warn("Failed to read external content", exception);
037        return status(BAD_GATEWAY).entity(exception.getMessage()).type(TEXT_PLAIN_WITH_CHARSET)
038            .build();
039    }
040
041}