diff --git a/Core/Utilities/Sources/Extensions/Error+Extension.swift b/Core/Utilities/Sources/Extensions/Error+Extension.swift new file mode 100644 index 00000000..5fde487e --- /dev/null +++ b/Core/Utilities/Sources/Extensions/Error+Extension.swift @@ -0,0 +1,26 @@ +// +// Error+Extension.swift +// +// +// Created by Mohamed Afifi on 2023-12-19. +// + +import Foundation + +extension Error { + public var isCancelled: Bool { + if self is CancellationError { + return true + } + + do { + throw self + } catch URLError.cancelled { + return true + } catch CocoaError.userCancelled { + return true + } catch { + return false + } + } +} diff --git a/Data/BatchDownloader/Sources/Downloader/DownloadBatchResponse.swift b/Data/BatchDownloader/Sources/Downloader/DownloadBatchResponse.swift index 03d52e7e..11b538b6 100644 --- a/Data/BatchDownloader/Sources/Downloader/DownloadBatchResponse.swift +++ b/Data/BatchDownloader/Sources/Downloader/DownloadBatchResponse.swift @@ -195,9 +195,7 @@ public actor DownloadBatchResponse { } if let error = firstError { - if !(error is CancellationError) { - crasher.recordError(error, reason: "Download failed \(batchId)") - } + crasher.recordError(error, reason: "Download failed \(batchId)") // Cancel other tasks if any has failed for request in requests { diff --git a/Data/BatchDownloader/Sources/Downloader/DownloadSessionDelegate.swift b/Data/BatchDownloader/Sources/Downloader/DownloadSessionDelegate.swift index 1a4932bf..857d97fd 100644 --- a/Data/BatchDownloader/Sources/Downloader/DownloadSessionDelegate.swift +++ b/Data/BatchDownloader/Sources/Downloader/DownloadSessionDelegate.swift @@ -176,10 +176,6 @@ private extension Error { (self as NSError).userInfo[NSURLSessionDownloadTaskResumeData] as? Data } - var isCancelled: Bool { - (self as? URLError)?.code == URLError.cancelled - } - func removeResumeData() -> Error { let error = self as NSError guard error.userInfo[NSURLSessionDownloadTaskResumeData] != nil else { diff --git a/Domain/ReadingService/Sources/ReadingResourcesService.swift b/Domain/ReadingService/Sources/ReadingResourcesService.swift index 4956e2e2..9df7597e 100644 --- a/Domain/ReadingService/Sources/ReadingResourcesService.swift +++ b/Domain/ReadingService/Sources/ReadingResourcesService.swift @@ -126,9 +126,7 @@ public actor ReadingResourcesService { return .ready } catch { - if !(error is CancellationError) { - crasher.recordError(error, reason: "Failed to download \(reading). Error: \(error)") - } + crasher.recordError(error, reason: "Failed to download \(reading). Error: \(error)") return .error(error as NSError) } } diff --git a/UI/NoorUI/BaseControllers/UIViewController+Error.swift b/UI/NoorUI/BaseControllers/UIViewController+Error.swift index cf18080b..85b18737 100644 --- a/UI/NoorUI/BaseControllers/UIViewController+Error.swift +++ b/UI/NoorUI/BaseControllers/UIViewController+Error.swift @@ -51,21 +51,3 @@ extension Error { return description ?? l("error.message.general") } } - -extension Error { - var isCancelled: Bool { - if self is CancellationError { - return true - } - - do { - throw self - } catch URLError.cancelled { - return true - } catch CocoaError.userCancelled { - return true - } catch { - return false - } - } -}