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.MementoDatetimeFormatException; 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 javax.ws.rs.core.Response.Status.BAD_REQUEST; 016import static org.slf4j.LoggerFactory.getLogger; 017import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET; 018import static javax.ws.rs.core.Response.status; 019 020/** 021 * Handle MementoDatetimeFormatException with HTTP 400 Bad Request. 022 * 023 * @author lsitu 024 * @since 2018-03-12 025 */ 026@Provider 027public class MementoDatetimeFormatExceptionMapper implements 028 ExceptionMapper<MementoDatetimeFormatException>, ExceptionDebugLogging { 029 030 private static final Logger LOGGER = getLogger(MementoDatetimeFormatExceptionMapper.class); 031 032 @Override 033 public Response toResponse(final MementoDatetimeFormatException e) { 034 debugException(this, e, LOGGER); 035 return status(BAD_REQUEST).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET) 036 .build(); 037 } 038}