
com.crosstreelabs.jaxrs.api.versioned.exception.ValidationExceptionMapper Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.crosstreelabs.jaxrs.api.versioned.exception;
import java.util.Collections;
import java.util.HashMap;
import javax.validation.ValidationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Provider
public class ValidationExceptionMapper implements ExceptionMapper {
private static final Logger LOGGER = LoggerFactory.getLogger(ValidationExceptionMapper.class);
@Override
public Response toResponse(final ValidationException exception) {
LOGGER.error(exception.getClass().getName()+": "+exception.getMessage());
LOGGER.debug("", exception);
return Response.status(Response.Status.BAD_REQUEST)
.entity(new HashMap<>(Collections.singletonMap("message", exception.getMessage())))
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy