1 package org.onap.vid.model;
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.commons.lang3.exception.ExceptionUtils;
5 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
6 import org.springframework.web.bind.annotation.ControllerAdvice;
7 import org.springframework.web.bind.annotation.ExceptionHandler;
8 import org.springframework.web.bind.annotation.ResponseBody;
9 import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
11 import static org.onap.vid.utils.Logging.getMethodCallerName;
14 public class ExceptionTranslator {
17 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExceptionTranslator.class);
19 @ExceptionHandler(MethodArgumentTypeMismatchException.class)
21 public ExceptionResponse handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
22 logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e);
23 Class<?> type = e.getRequiredType();
26 message = "The parameter " + e.getName() + " must have a value among : " + StringUtils.join(type.getEnumConstants(), ", ");
29 message = "The parameter " + e.getName() + " must be of type " + type.getTypeName();
31 return new ExceptionResponse(new ArgumentTypeMismatchException(message));
34 public static class ArgumentTypeMismatchException extends RuntimeException {
35 public ArgumentTypeMismatchException(String message) {