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 org.fcrepo.kernel.api.exception.ItemNotFoundException;
009import org.slf4j.Logger;
010
011import javax.ws.rs.core.Response;
012import javax.ws.rs.ext.ExceptionMapper;
013import javax.ws.rs.ext.Provider;
014
015import static org.slf4j.LoggerFactory.getLogger;
016
017
018/**
019 * Catch ItemNotFoundException
020 *
021 * @author pwinckles
022 */
023@Provider
024public class ItemNotFoundExceptionMapper implements
025        ExceptionMapper<ItemNotFoundException>, ExceptionDebugLogging {
026
027    private static final Logger LOGGER =
028        getLogger(ItemNotFoundExceptionMapper.class);
029
030    @Override
031    public Response toResponse(final ItemNotFoundException e) {
032        debugException(this, e, LOGGER);
033        return Response.status(Response.Status.NOT_FOUND).
034                entity("Error: " + e.getMessage()).build();
035    }
036}
037