优化文件获取异常处理
This commit is contained in:
@@ -21,6 +21,7 @@ import xtools.core.extend.TemplateUtils;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>Title : SysCommonFileController</p>
|
||||
@@ -51,7 +52,7 @@ public class SysCommonFileController {
|
||||
) {
|
||||
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
||||
response.setHeader("Cache-Control", "max-age=604800");
|
||||
sysFileOptService.download(id, outputStream, new SysFileDownloadCallback() {
|
||||
SysFileResp resp = sysFileOptService.download(id, outputStream, new SysFileDownloadCallback() {
|
||||
@Override
|
||||
public boolean before(SysFileResp fileInfo) {
|
||||
// 判断文件权限
|
||||
@@ -67,6 +68,9 @@ public class SysCommonFileController {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (Objects.isNull(resp)) {
|
||||
log.warn("文件获取失败,id={}", id);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("文件下载失败", e);
|
||||
throw new BizError("文件下载失败");
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
<!-- xtools end -->
|
||||
|
||||
<!-- 项目模块 begin -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-app-common-log-bus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-app-sys-api</artifactId>
|
||||
|
||||
@@ -16,6 +16,8 @@ import xtools.base.config.BaseParams;
|
||||
import xtools.boot.api.enums.FileDataType;
|
||||
import xtools.boot.api.exection.BizError;
|
||||
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.service.StorageService;
|
||||
import xtools.core.CollectionUtils;
|
||||
@@ -24,6 +26,7 @@ import xtools.core.HexUtils;
|
||||
import xtools.core.StringUtils;
|
||||
import xtools.core.UuidUtils;
|
||||
import xtools.core.encrypt.Md5Utils;
|
||||
import xtools.core.enums.LogLevel;
|
||||
import xtools.core.extend.CheckUtils;
|
||||
import xtools.core.time.CalendarUtils;
|
||||
import xtools.extend.encrypt.Sm3Utils;
|
||||
@@ -264,7 +267,12 @@ public class SysFileOptServiceImpl implements SysFileOptService, BaseParams {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
storageService.get(data.getBucket(), data.getFilePath(), outputStream);
|
||||
try {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user