Skip to content

Commit

Permalink
Remove duplicate Error.isCancelled (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamede1945 authored Dec 23, 2023
1 parent b811940 commit f5520e6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
26 changes: 26 additions & 0 deletions Core/Utilities/Sources/Extensions/Error+Extension.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions Domain/ReadingService/Sources/ReadingResourcesService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
18 changes: 0 additions & 18 deletions UI/NoorUI/BaseControllers/UIViewController+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit f5520e6

Please sign in to comment.