Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit b2b757f

Browse files
authored
Thread networking errors and add custom error descriptions (#2324)
* Better network error descriptions * localized descriptions for custom errors
1 parent 20ba8ac commit b2b757f

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

Classes/Repository/RepositoryCodeDirectoryViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import UIKit
1010
import IGListKit
1111
import TUSafariActivity
12+
import Squawk
1213

1314
final class RepositoryCodeDirectoryViewController: BaseListViewController<NSNumber>,
1415
BaseListViewControllerDataSource,
@@ -123,7 +124,8 @@ RepositoryBranchUpdatable {
123124
path: path.path
124125
) { [weak self] (result) in
125126
switch result {
126-
case .error:
127+
case .error(let error):
128+
Squawk.show(error: error)
127129
self?.error(animated: trueUnlessReduceMotionEnabled)
128130
case .success(let files):
129131
self?.files = files

Classes/Repository/RepositoryOverviewViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import UIKit
1010
import IGListKit
1111
import GitHubAPI
12+
import Squawk
1213

1314
class HackScrollIndicatorInsetsCollectionView: UICollectionView {
1415
override var scrollIndicatorInsets: UIEdgeInsets {
@@ -97,7 +98,8 @@ RepositoryBranchUpdatable {
9798
self?.update(animated: trueUnlessReduceMotionEnabled)
9899
}
99100
}
100-
case .failure:
101+
case .failure(let error):
102+
Squawk.show(error: error)
101103
self?.error(animated: trueUnlessReduceMotionEnabled)
102104
}
103105
}

Local Pods/GitHubAPI/GitHubAPI/ClientError.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import Foundation
1111
public enum ClientError: Error {
1212
case unauthorized
1313
case mismatchedInput
14-
case outputNil(Error?)
15-
case network(Error?)
14+
}
15+
16+
extension ClientError: LocalizedError {
17+
18+
public var localizedDescription: String {
19+
switch self {
20+
case .unauthorized:
21+
return NSLocalizedString("You are unauthorized to make this request.", comment: "")
22+
case .mismatchedInput:
23+
return NSLocalizedString("There was an error parsing this response.", comment: "")
24+
}
25+
}
26+
1627
}

Local Pods/GitHubAPI/GitHubAPI/Processing.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ internal func processResponse<T: Request>(
1414
response: HTTPURLResponse? = nil,
1515
error: Error? = nil
1616
) -> Result<T.ResponseType> {
17+
guard error == nil else {
18+
return .failure(error)
19+
}
1720
guard let input = input as? T.ResponseType.InputType else {
1821
return .failure(ClientError.mismatchedInput)
1922
}
20-
guard error == nil else {
21-
return .failure(ClientError.network(error))
22-
}
2323
do {
2424
let output = try T.ResponseType(input: input, response: response)
2525
return .success(output)
2626
} catch {
27-
return .failure(ClientError.outputNil(error))
27+
return .failure(error)
2828
}
2929
}
3030

0 commit comments

Comments
 (0)