Skip to content

Commit 842a4ad

Browse files
NSURLErrorCancelled does not show error modal
1 parent da4619b commit 842a4ad

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Created by Axel Ancona Esselmann on 7/9/24.
2+
//
3+
4+
import Foundation
5+
6+
public extension Error {
7+
var isCancellation: Bool {
8+
switch self {
9+
case is CancellationError: return true
10+
default:
11+
let nsError = self as NSError
12+
if nsError.domain == NSURLErrorDomain, nsError.code == NSURLErrorCancelled {
13+
return true
14+
} else {
15+
return false
16+
}
17+
}
18+
}
19+
}

Sources/LoadableView/Protocols/LoadableView/BaseLoadableViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public extension BaseLoadableViewModel {
4747
}
4848

4949
func setError(_ error: Error?) {
50-
if let error = error {
50+
if let error = error, !error.isCancellation {
5151
overlayState.send(.error(error))
5252
} else {
5353
overlayState.send(.none)

Sources/LoadableView/Protocols/LoadableView/IDedLoadableViewModel.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ public extension IDedLoadableViewModel {
6868
}
6969
viewState = .loaded(item)
7070
}
71-
catch is CancellationError {}
7271
catch {
73-
setError(error)
74-
return
72+
if !error.isCancellation {
73+
setError(error)
74+
return
75+
}
7576
}
7677
setIsLoading(false)
7778
}
@@ -96,10 +97,8 @@ public extension IDedLoadableViewModel {
9697
}
9798
setIsLoading(false)
9899
}
99-
catch is CancellationError {}
100100
catch {
101101
setError(error)
102-
return
103102
}
104103
}
105104

Sources/LoadableView/Protocols/LoadableView/LoadableViewModel.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public extension LoadableViewModel {
2525
}
2626
viewState = .loaded(item)
2727
}
28-
catch is CancellationError {}
2928
catch {
30-
setError(error)
31-
return
29+
if !error.isCancellation {
30+
setError(error)
31+
return
32+
}
3233
}
3334
setIsLoading(false)
3435
}
@@ -50,10 +51,8 @@ public extension LoadableViewModel {
5051
}
5152
setIsLoading(false)
5253
}
53-
catch is CancellationError {}
5454
catch {
5555
setError(error)
56-
return
5756
}
5857
}
5958

0 commit comments

Comments
 (0)