Przeglądaj źródła

refactor(minio): 优化文件操作异常处理

- 移除初始化 MinIO 和删除文件时的注释掉的异常抛出- 在下载、上传文件时增加异常抛出,提高错误处理的一致性
- 更新 pom.xml,添加项目描述和版本号
nahida 11 miesięcy temu
rodzic
commit
9f90f4f703

+ 2 - 0
pom.xml

@@ -9,6 +9,8 @@
 
     <artifactId>minioutil</artifactId>
     <packaging>jar</packaging>
+    <description>minio工具类</description>
+    <version>1.0.1</version>
 
     <name>minioutil</name>
     <url>http://maven.apache.org</url>

+ 8 - 0
src/main/java/com/zksy/service/impl/MinioFileStorageServiceImpl.java

@@ -44,6 +44,7 @@ public class MinioFileStorageServiceImpl implements MinioFileStorageService {
             log.info("初始化MinIO成功");
         } catch (Exception e) {
             log.error("初始化MinIO失败", e);
+//            throw new RuntimeException("初始化MinIO失败");
         }
     }
     @Override
@@ -52,6 +53,7 @@ public class MinioFileStorageServiceImpl implements MinioFileStorageService {
             minioClient.removeObject(RemoveObjectArgs.builder().bucket(minIOConfigProperties.getBucket()).object(fileName).build());
         } catch (Exception e) {
             log.error("删除文件失败", e);
+//            throw new RuntimeException("删除文件失败");
         }
     }
 
@@ -75,6 +77,7 @@ public class MinioFileStorageServiceImpl implements MinioFileStorageService {
             out.close();
         } catch (Exception e) {
             log.error("下载文件失败", e);
+            throw new RuntimeException("下载文件失败");
         }
     }
 
@@ -98,6 +101,7 @@ public class MinioFileStorageServiceImpl implements MinioFileStorageService {
             );
         } catch (Exception e) {
             log.error("上传文件失败", e);
+            throw new Exception("上传文件失败");
         }
         return filePath;
     }
@@ -114,6 +118,9 @@ public class MinioFileStorageServiceImpl implements MinioFileStorageService {
                             .stream(inputStream, file.length(), ObjectWriteArgs.MIN_MULTIPART_SIZE)
                             .build()
             );
+        }catch (Exception e) {
+            log.error("上传文件失败", e);
+            throw new Exception("上传文件失败");
         }
         return filePath;
     }
@@ -150,6 +157,7 @@ public class MinioFileStorageServiceImpl implements MinioFileStorageService {
                 resList.add(s);
             }catch (Exception e){
                 log.error("上传文件失败", e);
+                throw new RuntimeException("上传文件失败");
             }
         });
         return resList;