|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.shxy.xymanager_common.exception;
|
|
|
|
|
|
|
|
|
|
import com.shxy.xymanager_common.base.ResponseReult;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.validation.FieldError;
|
|
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
|
@ -15,11 +16,13 @@ import java.sql.SQLException;
|
|
|
|
|
* Created by 晶晶 on 2023/5/8.
|
|
|
|
|
*/
|
|
|
|
|
@ControllerAdvice
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class GlobalExceptionHandler {
|
|
|
|
|
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@ExceptionHandler(value = ApiException.class)
|
|
|
|
|
public ResponseReult handleApiException(ApiException e) {
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
if (e.getErrorCode() != null) {
|
|
|
|
|
return ResponseReult.error(e.getErrorCode());
|
|
|
|
|
}
|
|
|
|
@ -32,6 +35,7 @@ public class GlobalExceptionHandler {
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@ExceptionHandler(value = SQLException.class)
|
|
|
|
|
public ResponseReult handleSQLException(SQLException e) {
|
|
|
|
|
log.error("", e);
|
|
|
|
|
int errorCode = e.getErrorCode();
|
|
|
|
|
String message = e.getMessage();
|
|
|
|
|
return ResponseReult.fail(errorCode, message);
|
|
|
|
@ -54,6 +58,7 @@ public class GlobalExceptionHandler {
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@ExceptionHandler(value = Exception.class)
|
|
|
|
|
public ResponseReult handleException(Exception e) {
|
|
|
|
|
log.error("", e);
|
|
|
|
|
String message = e.getMessage();
|
|
|
|
|
return ResponseReult.error(message);
|
|
|
|
|
}
|
|
|
|
|