refactor: MinIO 上传图片返回名称不带文件夹和全局异常支持自定义异常信息。

This commit is contained in:
Ray.Hao
2025-01-22 11:56:58 +08:00
parent 8bd38f6302
commit c2ab755cf3
6 changed files with 58 additions and 42 deletions

View File

@@ -20,6 +20,13 @@ public class BusinessException extends RuntimeException {
this.resultCode = errorCode;
}
public BusinessException(IResultCode errorCode,String message) {
super(message);
this.resultCode = errorCode;
}
public BusinessException(String message, Throwable cause) {
super(message, cause);
}

View File

@@ -30,7 +30,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 全局系统异常处理器
* <p>
@@ -219,9 +218,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public <T> Result<T> handleBizException(BusinessException e) {
log.error("biz exception: {}", e.getMessage());
log.error("biz exception", e);
if (e.getResultCode() != null) {
return Result.failed(e.getResultCode());
return Result.failed(e.getResultCode(), e.getMessage());
}
return Result.failed(e.getMessage());
}
@@ -239,8 +238,7 @@ public class GlobalExceptionHandler {
|| e instanceof AuthenticationException) {
throw e;
}
log.error("unknown exception: {}", e.getMessage());
e.printStackTrace();
log.error("unknown exception", e);
return Result.failed(e.getLocalizedMessage());
}