|
@@ -4,10 +4,13 @@ import com.fdkankan.manage.common.ResultCode;
|
|
import com.fdkankan.manage.common.ResultData;
|
|
import com.fdkankan.manage.common.ResultData;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
|
|
|
|
+import java.sql.SQLIntegrityConstraintViolationException;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 全局异常处理器
|
|
* 全局异常处理器
|
|
*/
|
|
*/
|
|
@@ -47,4 +50,17 @@ public class GlobalExceptionHandler {
|
|
}
|
|
}
|
|
return ResultData.error( 500, e.getCause().getMessage());
|
|
return ResultData.error( 500, e.getCause().getMessage());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理业务异常
|
|
|
|
+ */
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @ExceptionHandler(value = SQLIntegrityConstraintViolationException.class)
|
|
|
|
+ public ResultData SQLIntegrityConstraintViolationException(SQLIntegrityConstraintViolationException e) {
|
|
|
|
+ log.error("mysql服务错误:", e);
|
|
|
|
+ if(e.getCause().getMessage().contains("Duplicate entry")){
|
|
|
|
+ return ResultData.error(ResultCode.UNQUINX_INDEX.code(),ResultCode.UNQUINX_INDEX.message());
|
|
|
|
+ }
|
|
|
|
+ return ResultData.error( 500, e.getCause().getMessage());
|
|
|
|
+ }
|
|
}
|
|
}
|