Explorar o código

chain .catch to avoid promise rejection in AssetsManager (#1238)

Klaudiusz Dembler %!s(int64=3) %!d(string=hai) anos
pai
achega
9dcea374b6
Modificáronse 1 ficheiros con 18 adicións e 17 borrados
  1. 18 17
      src/providers/assets/assetsManager.tsx

+ 18 - 17
src/providers/assets/assetsManager.tsx

@@ -55,24 +55,25 @@ export const AssetsManager: React.FC = () => {
           assetUrl,
         }
 
-        assetTestPromise.then((responseTime) => {
-          if (resolutionData.assetType === AssetType.MEDIA) {
-            // we're currently skipping monitoring video files as it's hard to measure their performance
-            // image assets are easy to measure but videos vary in length and size
-            // we will be able to handle that once we can access more detailed response timing
-            return
-          }
+        assetTestPromise
+          .then((responseTime) => {
+            if (resolutionData.assetType === AssetType.MEDIA) {
+              // we're currently skipping monitoring video files as it's hard to measure their performance
+              // image assets are easy to measure but videos vary in length and size
+              // we will be able to handle that once we can access more detailed response timing
+              return
+            }
 
-          // if response takes <20ms assume it's coming from cache
-          // we shouldn't need that once we can do detailed timing, then we can check directly
-          if (responseTime > 20) {
-            AssetLogger.assetResponseMetric(assetDetails, responseTime)
-          }
-        })
-        assetTestPromise.catch(() => {
-          AssetLogger.assetError(assetDetails)
-          ConsoleLogger.error('Failed to load asset', assetDetails)
-        })
+            // if response takes <20ms assume it's coming from cache
+            // we shouldn't need that once we can do detailed timing, then we can check directly
+            if (responseTime > 20) {
+              AssetLogger.assetResponseMetric(assetDetails, responseTime)
+            }
+          })
+          .catch(() => {
+            AssetLogger.assetError(assetDetails)
+            ConsoleLogger.error('Failed to load asset', assetDetails)
+          })
         const assetTestPromiseWithTimeout = withTimeout(assetTestPromise, ASSET_RESPONSE_TIMEOUT)
 
         try {