Browse Source

StoreService 中返回有效数据或抛出异常

reghao 1 year ago
parent
commit
e95a2b1a89

+ 3 - 2
oss-api/src/main/java/cn/reghao/oss/api/iface/StoreService.java

@@ -27,8 +27,9 @@ public interface StoreService {
     void setObjectScope(String objectId, int scope);
     void deleteByObjectId(String objectId);
     void deleteByObjectName(String objectName, int owner);
-    ObjectInfo getObjectInfo(String objectId);
-    String getSignedUrl(String domain, int owner, String objectId, int expire);
+
+    ObjectInfo getObjectInfo(String objectId) throws Exception;
+    String getSignedUrl(String domain, int owner, String objectId, int expire) throws Exception;
 
     VideoInfo getVideoInfo(String objectId) throws Exception;
     ImageInfo getImageInfo(String objectId) throws Exception;

+ 9 - 3
oss-store/src/main/java/cn/reghao/oss/store/rpc/StoreServiceImpl.java

@@ -130,10 +130,11 @@ public class StoreServiceImpl implements StoreService {
     }
 
     @Override
-    public ObjectInfo getObjectInfo(String objectId) {
+    public ObjectInfo getObjectInfo(String objectId) throws Exception {
         FileMeta fileMeta = objectRepository.getByObjectId(objectId);
         if (fileMeta == null) {
-            return null;
+            String errMsg = String.format("%s not exist in oss-store", objectId);
+            throw new Exception(errMsg);
         }
 
         return getObjectInfo(fileMeta);
@@ -150,8 +151,13 @@ public class StoreServiceImpl implements StoreService {
     }
 
     @Override
-    public String getSignedUrl(String domain, int owner, String objectId, int expire) {
+    public String getSignedUrl(String domain, int owner, String objectId, int expire) throws Exception {
         ObjectMeta objectMeta = objectRepository.getObjectMetaById(objectId);
+        if (objectMeta == null) {
+            String errMsg = String.format("%s not exist in oss-store", objectId);
+            throw new Exception(errMsg);
+        }
+
         String url = String.format("//%s/%s", domain, objectMeta.getObjectName());
         return signService.getSignedUrl(owner, url, expire);
     }