Merge branch 'feature1' into develop
This commit is contained in:
@@ -17,6 +17,7 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||||
|
|
||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
public ResponseEntity<ResponseModel<?>> handleValidation(MethodArgumentNotValidException ex) {
|
public ResponseEntity<ResponseModel<?>> handleValidation(MethodArgumentNotValidException ex) {
|
||||||
List<Map<String, String>> fieldErrors = ex.getBindingResult().getFieldErrors()
|
List<Map<String, String>> fieldErrors = ex.getBindingResult().getFieldErrors()
|
||||||
@@ -43,6 +44,19 @@ public class GlobalExceptionHandler {
|
|||||||
return ResponseEntity.status(HttpStatus.valueOf(ex.getStatusCode())).body(resp);
|
return ResponseEntity.status(HttpStatus.valueOf(ex.getStatusCode())).body(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(CustomException.class)
|
||||||
|
public ResponseEntity<ResponseModel<?>> handleCustomException(CustomException ex) {
|
||||||
|
logger.warn("CustomException: {}", ex.getMessage());
|
||||||
|
ResponseModel<?> resp = new ResponseModel<>(
|
||||||
|
ex.getMessage(),
|
||||||
|
"FAILED",
|
||||||
|
HttpStatus.BAD_REQUEST.value(),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseEntity<ResponseModel<?>> handleAll(Exception ex) {
|
public ResponseEntity<ResponseModel<?>> handleAll(Exception ex) {
|
||||||
logger.error("Unhandled exception", ex);
|
logger.error("Unhandled exception", ex);
|
||||||
|
|||||||
Reference in New Issue
Block a user