fix: 补充异常报错

dev
huangfeng 1 year ago
parent a19dff9596
commit da64cd2209

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

Loading…
Cancel
Save