Pārlūkot izejas kodu

Un-nest `catch` clauses

Iggy Drougge 3 gadi atpakaļ
vecāks
revīzija
964b62d616
1 mainītis faili ar 6 papildinājumiem un 11 dzēšanām
  1. 6 11
      Sources/Cache/ImageCache.swift

+ 6 - 11
Sources/Cache/ImageCache.swift

@@ -609,12 +609,10 @@ open class ImageCache {
                     image = options.cacheSerializer.image(with: data, options: options)
                 }
                 callbackQueue.execute { completionHandler(.success(image)) }
+            } catch let error as KingfisherError {
+                callbackQueue.execute { completionHandler(.failure(error)) }
             } catch {
-                if let error = error as? KingfisherError {
-                    callbackQueue.execute { completionHandler(.failure(error)) }
-                } else {
-                    assertionFailure("The internal thrown error should be a `KingfisherError`.")
-                }
+                assertionFailure("The internal thrown error should be a `KingfisherError`.")
             }
         }
     }
@@ -810,13 +808,10 @@ open class ImageCache {
             do {
                 let size = try self.diskStorage.totalSize()
                 DispatchQueue.main.async { handler(.success(size)) }
+            } catch let error as KingfisherError {
+                DispatchQueue.main.async { handler(.failure(error)) }
             } catch {
-                if let error = error as? KingfisherError {
-                    DispatchQueue.main.async { handler(.failure(error)) }
-                } else {
-                    assertionFailure("The internal thrown error should be a `KingfisherError`.")
-                }
-                
+                assertionFailure("The internal thrown error should be a `KingfisherError`.")
             }
         }
     }