Procházet zdrojové kódy

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

Klaudiusz Dembler před 3 roky
rodič
revize
9dcea374b6
1 změnil soubory, kde provedl 18 přidání a 17 odebrání
  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 {