T203 added javadoc
This commit is contained in:
@@ -10,10 +10,20 @@ import javax.validation.ConstraintViolationException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
//TODO: Find usage and document or remove it
|
//TODO: Is it really necessary?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom exception handler for {@link ConstraintViolationException}
|
||||||
|
* @author Rafał Żukowicz
|
||||||
|
*/
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class MvcExceptionHandler {
|
public class MvcExceptionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides handling for {@link ConstraintViolationException}
|
||||||
|
* @param e exception argument
|
||||||
|
* @return response with error list and status 400 bad request
|
||||||
|
*/
|
||||||
@ExceptionHandler(ConstraintViolationException.class)
|
@ExceptionHandler(ConstraintViolationException.class)
|
||||||
public ResponseEntity<List> validationErrorHandler(ConstraintViolationException e){
|
public ResponseEntity<List> validationErrorHandler(ConstraintViolationException e){
|
||||||
List<String> errors = new ArrayList<>(e.getConstraintViolations().size());
|
List<String> errors = new ArrayList<>(e.getConstraintViolations().size());
|
||||||
@@ -24,6 +34,11 @@ public class MvcExceptionHandler {
|
|||||||
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides handling for {@link BindException}
|
||||||
|
* @param ex exception argument
|
||||||
|
* @return response with error list and status 400 bad request
|
||||||
|
*/
|
||||||
@ExceptionHandler(BindException.class)
|
@ExceptionHandler(BindException.class)
|
||||||
public ResponseEntity<List> handleBindException(BindException ex){
|
public ResponseEntity<List> handleBindException(BindException ex){
|
||||||
return new ResponseEntity(ex.getAllErrors(), HttpStatus.BAD_REQUEST);
|
return new ResponseEntity(ex.getAllErrors(), HttpStatus.BAD_REQUEST);
|
||||||
|
|||||||
Reference in New Issue
Block a user