forked from Annex5061/java-algorithms
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationExceptionHandler.java
More file actions
Latest commit
35 lines (27 loc) · 1.25 KB
/
Copy pathApplicationExceptionHandler.java
File metadata and controls
35 lines (27 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
packagecom.simactivation.advice;
importjava.util.HashMap;
importjava.util.Map;
importorg.springframework.http.HttpStatus;
importorg.springframework.web.bind.MethodArgumentNotValidException;
importorg.springframework.web.bind.annotation.ExceptionHandler;
importorg.springframework.web.bind.annotation.ResponseStatus;
importorg.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
publicclassApplicationExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
publicMap<String, String> handleInvalidArgument(MethodArgumentNotValidExceptionex) {
Map<String, String> errorMap = newHashMap<>();
ex.getBindingResult().getFieldErrors().forEach(error -> {
errorMap.put(error.getField(), error.getDefaultMessage());
});
returnerrorMap;
}
// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
// @ExceptionHandler(UserNotFoundException.class)
// public Map<String, String> handleBusinessException(UserNotFoundException ex) {
// Map<String, String> errorMap = new HashMap<>();
// errorMap.put("errorMessage", ex.getMessage());
// return errorMap;
// }
}