优化文件获取异常处理

This commit is contained in:
2026-05-08 09:24:15 +08:00
parent 903032623a
commit a7189ec41b
3 changed files with 19 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ import xtools.core.extend.TemplateUtils;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects;
/** /**
* <p>Title : SysCommonFileController</p> * <p>Title : SysCommonFileController</p>
@@ -51,7 +52,7 @@ public class SysCommonFileController {
) { ) {
try (ServletOutputStream outputStream = response.getOutputStream()) { try (ServletOutputStream outputStream = response.getOutputStream()) {
response.setHeader("Cache-Control", "max-age=604800"); response.setHeader("Cache-Control", "max-age=604800");
sysFileOptService.download(id, outputStream, new SysFileDownloadCallback() { SysFileResp resp = sysFileOptService.download(id, outputStream, new SysFileDownloadCallback() {
@Override @Override
public boolean before(SysFileResp fileInfo) { public boolean before(SysFileResp fileInfo) {
// 判断文件权限 // 判断文件权限
@@ -67,6 +68,9 @@ public class SysCommonFileController {
return true; return true;
} }
}); });
if (Objects.isNull(resp)) {
log.warn("文件获取失败,id={}", id);
}
} catch (IOException e) { } catch (IOException e) {
log.error("文件下载失败", e); log.error("文件下载失败", e);
throw new BizError("文件下载失败"); throw new BizError("文件下载失败");

View File

@@ -33,6 +33,11 @@
<!-- xtools end --> <!-- xtools end -->
<!-- 项目模块 begin --> <!-- 项目模块 begin -->
<dependency>
<groupId>org.xujun</groupId>
<artifactId>xtools-app-common-log-bus</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.xujun</groupId> <groupId>org.xujun</groupId>
<artifactId>xtools-app-sys-api</artifactId> <artifactId>xtools-app-sys-api</artifactId>

View File

@@ -16,6 +16,8 @@ import xtools.base.config.BaseParams;
import xtools.boot.api.enums.FileDataType; import xtools.boot.api.enums.FileDataType;
import xtools.boot.api.exection.BizError; import xtools.boot.api.exection.BizError;
import xtools.boot.api.model.dto.Result; import xtools.boot.api.model.dto.Result;
import xtools.boot.log.LogBus;
import xtools.boot.log.enums.LogBusBaseType;
import xtools.boot.storage.base.config.StorageConfig; import xtools.boot.storage.base.config.StorageConfig;
import xtools.boot.storage.base.service.StorageService; import xtools.boot.storage.base.service.StorageService;
import xtools.core.CollectionUtils; import xtools.core.CollectionUtils;
@@ -24,6 +26,7 @@ import xtools.core.HexUtils;
import xtools.core.StringUtils; import xtools.core.StringUtils;
import xtools.core.UuidUtils; import xtools.core.UuidUtils;
import xtools.core.encrypt.Md5Utils; import xtools.core.encrypt.Md5Utils;
import xtools.core.enums.LogLevel;
import xtools.core.extend.CheckUtils; import xtools.core.extend.CheckUtils;
import xtools.core.time.CalendarUtils; import xtools.core.time.CalendarUtils;
import xtools.extend.encrypt.Sm3Utils; import xtools.extend.encrypt.Sm3Utils;
@@ -264,7 +267,12 @@ public class SysFileOptServiceImpl implements SysFileOptService, BaseParams {
return data; return data;
} }
} }
try {
storageService.get(data.getBucket(), data.getFilePath(), outputStream); storageService.get(data.getBucket(), data.getFilePath(), outputStream);
} catch (Exception e) {
LogBus.init(LogLevel.ERROR, LogBusBaseType.STORAGE).data(data).print(false).error(e).save();
return null;
}
return data; return data;
} }