diff --git a/src/main/java/edu/umd/dawn/common/entities/User.java b/src/main/java/edu/umd/dawn/common/entities/User.java index 7a7eedc7a57b8ac42a7983a817e8c1e99391e855..1262fe15e7b7d284ece57f99347406d049bbc75f 100644 --- a/src/main/java/edu/umd/dawn/common/entities/User.java +++ b/src/main/java/edu/umd/dawn/common/entities/User.java @@ -1,9 +1,7 @@ package edu.umd.dawn.common.entities; - import edu.umd.dawn.common.exceptions.DawnException; import edu.umd.dawn.common.exceptions.DawnExceptionParameters; - import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -87,10 +85,11 @@ public class User { locations.stream().filter(location -> !location.equals(id)).collect(Collectors.toList()); if (newList.size() == locations.size()) { - throw new DawnException(new DawnExceptionParameters(400, "BAD_REQUEST", "location id provided does not exist", "")); + throw new DawnException( + new DawnExceptionParameters(400, "BAD_REQUEST", "location id provided does not exist", "")); } setLocations(newList); return id; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/umd/dawn/common/enums/Product.java b/src/main/java/edu/umd/dawn/common/enums/Product.java index 94083a961c8a3ce69136bd44030b3a9acd21d065..aa4440b8a87993dc228d181870ca34405612b9fd 100644 --- a/src/main/java/edu/umd/dawn/common/enums/Product.java +++ b/src/main/java/edu/umd/dawn/common/enums/Product.java @@ -1,7 +1,7 @@ package edu.umd.dawn.common.enums; -import edu.umd.dawn.common.exceptions.DawnException; import edu.umd.dawn.common.exceptions.BaseExceptions; +import edu.umd.dawn.common.exceptions.DawnException; import java.util.Map; public enum Product { diff --git a/src/main/java/edu/umd/dawn/common/exceptions/BaseExceptions.java b/src/main/java/edu/umd/dawn/common/exceptions/BaseExceptions.java index 141384bafb6c50fa0f192793567177feac2c2cc8..09ed60fa83c2a0ae6df40a7c4b4d4ee3bb023cce 100644 --- a/src/main/java/edu/umd/dawn/common/exceptions/BaseExceptions.java +++ b/src/main/java/edu/umd/dawn/common/exceptions/BaseExceptions.java @@ -10,15 +10,15 @@ public class BaseExceptions { public static final DawnExceptionParameters BAD_REQUEST = new DawnExceptionParameters(400, "BAD_REQUEST", "Invalid request submitted", ""); - + public static final DawnExceptionParameters INTERNAL_SERVER_ERROR = new DawnExceptionParameters(500, "INTERNAL_SERVER_ERROR", "Internal server error", ""); public static final DawnExceptionParameters OUT_OF_BOUNDS = new DawnExceptionParameters(500, "INTERNAL_SERVER_ERROR", "Internal server error", "out of bounds"); public static final DawnExceptionParameters UNHANDLED_INTERNAL_SERVER_ERROR = new DawnExceptionParameters(500, "INTERNAL_SERVER_ERROR", "Internal server error", "unhandled error"); - - public static final DawnExceptionParameters SERVICE_UNAVAILABLE = + + public static final DawnExceptionParameters SERVICE_UNAVAILABLE = new DawnExceptionParameters(503, "SERVICE_UNAVAILABLE", "service unavailable", ""); public static final DawnExceptionParameters FORBIDDEN = @@ -36,6 +36,6 @@ public class BaseExceptions { return new DawnExceptionParameters(400, "BAD_REQUEST", String.format("offset of %d is invalid", offset), ""); } - public static final DawnExceptionParameters PRODUCT_UNSUPPORTED = new DawnExceptionParameters( - 400, "BAD_REQUEST", "This operation is unsupported for provided product", ""); + public static final DawnExceptionParameters PRODUCT_UNSUPPORTED = + new DawnExceptionParameters(400, "BAD_REQUEST", "This operation is unsupported for provided product", ""); } diff --git a/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java b/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java index 33e711aa43c1d7ad904c0470ff902808d9a99d3e..4a5a593b38c286db8682957cb6cb083ba1772fc6 100644 --- a/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java +++ b/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java @@ -4,7 +4,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.Map; import java.util.Set; - import lombok.extern.slf4j.Slf4j; import org.slf4j.MDC; import org.springframework.beans.ConversionNotSupportedException; @@ -36,21 +35,20 @@ import org.springframework.web.servlet.NoHandlerFoundException; public class CustomExceptionHandler { private final Map<Class<?>, DawnExceptionParameters> MVC_EXCEPTION_MAP = Map.ofEntries( - Map.entry(HttpRequestMethodNotSupportedException.class, BaseExceptions.METHOD_NOT_ALLOWED), - Map.entry(HttpMediaTypeNotSupportedException.class, BaseExceptions.UNSUPPORTED_MEDIA_TYPE), - Map.entry(HttpMediaTypeNotAcceptableException.class, BaseExceptions.NOT_ACCEPTABLE), - Map.entry(MissingPathVariableException.class, BaseExceptions.INTERNAL_SERVER_ERROR), - Map.entry(MissingServletRequestParameterException.class, BaseExceptions.BAD_REQUEST), - Map.entry(ServletRequestBindingException.class, BaseExceptions.BAD_REQUEST), - Map.entry(ConversionNotSupportedException.class, BaseExceptions.INTERNAL_SERVER_ERROR), - Map.entry(TypeMismatchException.class, BaseExceptions.BAD_REQUEST), - Map.entry(HttpMessageNotReadableException.class, BaseExceptions.BAD_REQUEST), - Map.entry(HttpMessageNotWritableException.class, BaseExceptions.INTERNAL_SERVER_ERROR), - Map.entry(MethodArgumentNotValidException.class, BaseExceptions.BAD_REQUEST), - Map.entry(MissingServletRequestPartException.class, BaseExceptions.BAD_REQUEST), - Map.entry(NoHandlerFoundException.class, BaseExceptions.NOT_FOUND), - Map.entry(AsyncRequestTimeoutException.class, BaseExceptions.SERVICE_UNAVAILABLE) - ); + Map.entry(HttpRequestMethodNotSupportedException.class, BaseExceptions.METHOD_NOT_ALLOWED), + Map.entry(HttpMediaTypeNotSupportedException.class, BaseExceptions.UNSUPPORTED_MEDIA_TYPE), + Map.entry(HttpMediaTypeNotAcceptableException.class, BaseExceptions.NOT_ACCEPTABLE), + Map.entry(MissingPathVariableException.class, BaseExceptions.INTERNAL_SERVER_ERROR), + Map.entry(MissingServletRequestParameterException.class, BaseExceptions.BAD_REQUEST), + Map.entry(ServletRequestBindingException.class, BaseExceptions.BAD_REQUEST), + Map.entry(ConversionNotSupportedException.class, BaseExceptions.INTERNAL_SERVER_ERROR), + Map.entry(TypeMismatchException.class, BaseExceptions.BAD_REQUEST), + Map.entry(HttpMessageNotReadableException.class, BaseExceptions.BAD_REQUEST), + Map.entry(HttpMessageNotWritableException.class, BaseExceptions.INTERNAL_SERVER_ERROR), + Map.entry(MethodArgumentNotValidException.class, BaseExceptions.BAD_REQUEST), + Map.entry(MissingServletRequestPartException.class, BaseExceptions.BAD_REQUEST), + Map.entry(NoHandlerFoundException.class, BaseExceptions.NOT_FOUND), + Map.entry(AsyncRequestTimeoutException.class, BaseExceptions.SERVICE_UNAVAILABLE)); @Value("${config.serviceName}") private String source; @@ -107,7 +105,7 @@ public class CustomExceptionHandler { ArrayIndexOutOfBoundsException exception, WebRequest webRequest) { return wrapExceptionAs(exception, BaseExceptions.OUT_OF_BOUNDS); } - + @ExceptionHandler(DawnException.class) public ResponseEntity<Object> handleDawnExceptions(DawnException exception, WebRequest webRequest) { return returnDawnException(exception); @@ -153,6 +151,6 @@ public class CustomExceptionHandler { @ExceptionHandler(Throwable.class) public ResponseEntity<Object> handleUnHandledException(Throwable exception, WebRequest webRequest) { - return wrapExceptionAs((Exception)exception, BaseExceptions.UNHANDLED_INTERNAL_SERVER_ERROR); + return wrapExceptionAs((Exception) exception, BaseExceptions.UNHANDLED_INTERNAL_SERVER_ERROR); } }