diff --git a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/exceptions/RestResponseEntityExceptionHandler.java b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/exceptions/RestResponseEntityExceptionHandler.java index 17ba4421930c436d8a0e60fd9594bd997ce27f85..6d3d235510dec1076435540abecda8381fd7dc0c 100644 --- a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/exceptions/RestResponseEntityExceptionHandler.java +++ b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/exceptions/RestResponseEntityExceptionHandler.java @@ -7,7 +7,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.util.UrlPathHelper; @@ -41,7 +40,7 @@ public class RestResponseEntityExceptionHandler { * @param request request * @return response entity */ - @ExceptionHandler(value = {MethodArgumentNotValidException.class, HttpMessageNotReadableException.class}) + @ExceptionHandler(value = {MethodArgumentNotValidException.class}) public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) { List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors() .stream() @@ -55,6 +54,22 @@ public class RestResponseEntityExceptionHandler { return buildResponseEntity(error); } + /** + * Handle MessageNotReadable exceptions + * + * @param ex exception + * @param request request + * @return response entity + */ + @ExceptionHandler(value = {HttpMessageNotReadableException.class}) + public ResponseEntity<ApiError> handleMessageNotReadableErrors(HttpMessageNotReadableException ex, HttpServletRequest request) { + ApiError error = new ApiError( + HttpStatus.BAD_REQUEST, + ex, + URL_PATH_HELPER.getRequestUri(request)); + return buildResponseEntity(error); + } + /** * Handle exceptions not matched by above handler methods * diff --git a/application/module-exercise/src/main/java/org/fuseri/moduleexercise/exceptions/RestResponseEntityExceptionHandler.java b/application/module-exercise/src/main/java/org/fuseri/moduleexercise/exceptions/RestResponseEntityExceptionHandler.java index 04b438126aec94aace781412f58ed51f4f8688c9..614139b6f8f7992b44dd42d719c2148da6154f46 100644 --- a/application/module-exercise/src/main/java/org/fuseri/moduleexercise/exceptions/RestResponseEntityExceptionHandler.java +++ b/application/module-exercise/src/main/java/org/fuseri/moduleexercise/exceptions/RestResponseEntityExceptionHandler.java @@ -40,7 +40,7 @@ public class RestResponseEntityExceptionHandler { * @param request request * @return response entity */ - @ExceptionHandler(value = {MethodArgumentNotValidException.class, HttpMessageNotReadableException.class}) + @ExceptionHandler(value = {MethodArgumentNotValidException.class}) public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) { List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors() .stream() @@ -54,6 +54,22 @@ public class RestResponseEntityExceptionHandler { return buildResponseEntity(error); } + /** + * Handle MessageNotReadable exceptions + * + * @param ex exception + * @param request request + * @return response entity + */ + @ExceptionHandler(value = {HttpMessageNotReadableException.class}) + public ResponseEntity<ApiError> handleMessageNotReadableErrors(HttpMessageNotReadableException ex, HttpServletRequest request) { + ApiError error = new ApiError( + HttpStatus.BAD_REQUEST, + ex, + URL_PATH_HELPER.getRequestUri(request)); + return buildResponseEntity(error); + } + /** * Handle exceptions not matched by above handler methods * diff --git a/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/exceptions/RestResponseEntityExceptionHandler.java b/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/exceptions/RestResponseEntityExceptionHandler.java index 3d5ae95b25706edb108dae7e929dab9fe2b48036..dd55d24356f2184a27fdc082be8e9c9acf566699 100644 --- a/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/exceptions/RestResponseEntityExceptionHandler.java +++ b/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/exceptions/RestResponseEntityExceptionHandler.java @@ -90,7 +90,7 @@ public class RestResponseEntityExceptionHandler { * @param request request * @return response entity */ - @ExceptionHandler(value = {MethodArgumentNotValidException.class, HttpMessageNotReadableException.class}) + @ExceptionHandler(value = {MethodArgumentNotValidException.class}) public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) { List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors() .stream() @@ -104,6 +104,22 @@ public class RestResponseEntityExceptionHandler { return buildResponseEntity(error); } + /** + * Handle MessageNotReadable exceptions + * + * @param ex exception + * @param request request + * @return response entity + */ + @ExceptionHandler(value = {HttpMessageNotReadableException.class}) + public ResponseEntity<ApiError> handleMessageNotReadableErrors(HttpMessageNotReadableException ex, HttpServletRequest request) { + ApiError error = new ApiError( + HttpStatus.BAD_REQUEST, + ex, + URL_PATH_HELPER.getRequestUri(request)); + return buildResponseEntity(error); + } + /** * Handle exceptions not matched by above handler methods *