Skip to content
Snippets Groups Projects
Commit 02cf26b0 authored by Dominika Zemanovičová's avatar Dominika Zemanovičová
Browse files

Separate errors for finding suitable resolvers

parent a6b5aab7
No related branches found
No related tags found
1 merge request!44fixed ConfidentialClientApplication
Pipeline #
This commit is part of merge request !44. Comments created here will be created in the context of that merge request.
...@@ -7,7 +7,6 @@ import org.springframework.http.HttpStatus; ...@@ -7,7 +7,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException; 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.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.util.UrlPathHelper; import org.springframework.web.util.UrlPathHelper;
...@@ -41,7 +40,7 @@ public class RestResponseEntityExceptionHandler { ...@@ -41,7 +40,7 @@ public class RestResponseEntityExceptionHandler {
* @param request request * @param request request
* @return response entity * @return response entity
*/ */
@ExceptionHandler(value = {MethodArgumentNotValidException.class, HttpMessageNotReadableException.class}) @ExceptionHandler(value = {MethodArgumentNotValidException.class})
public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) { public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) {
List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors() List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors()
.stream() .stream()
...@@ -55,6 +54,22 @@ public class RestResponseEntityExceptionHandler { ...@@ -55,6 +54,22 @@ public class RestResponseEntityExceptionHandler {
return buildResponseEntity(error); 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 * Handle exceptions not matched by above handler methods
* *
......
...@@ -40,7 +40,7 @@ public class RestResponseEntityExceptionHandler { ...@@ -40,7 +40,7 @@ public class RestResponseEntityExceptionHandler {
* @param request request * @param request request
* @return response entity * @return response entity
*/ */
@ExceptionHandler(value = {MethodArgumentNotValidException.class, HttpMessageNotReadableException.class}) @ExceptionHandler(value = {MethodArgumentNotValidException.class})
public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) { public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) {
List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors() List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors()
.stream() .stream()
...@@ -54,6 +54,22 @@ public class RestResponseEntityExceptionHandler { ...@@ -54,6 +54,22 @@ public class RestResponseEntityExceptionHandler {
return buildResponseEntity(error); 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 * Handle exceptions not matched by above handler methods
* *
......
...@@ -90,7 +90,7 @@ public class RestResponseEntityExceptionHandler { ...@@ -90,7 +90,7 @@ public class RestResponseEntityExceptionHandler {
* @param request request * @param request request
* @return response entity * @return response entity
*/ */
@ExceptionHandler(value = {MethodArgumentNotValidException.class, HttpMessageNotReadableException.class}) @ExceptionHandler(value = {MethodArgumentNotValidException.class})
public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) { public ResponseEntity<ApiError> handleValidationErrors(MethodArgumentNotValidException ex, HttpServletRequest request) {
List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors() List<ApiSubError> subErrors = ex.getBindingResult().getFieldErrors()
.stream() .stream()
...@@ -104,6 +104,22 @@ public class RestResponseEntityExceptionHandler { ...@@ -104,6 +104,22 @@ public class RestResponseEntityExceptionHandler {
return buildResponseEntity(error); 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 * Handle exceptions not matched by above handler methods
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment