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

Thread networking errors and add custom error descriptions #2324

Merged
merged 2 commits into from
Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit
import IGListKit
import TUSafariActivity
import Squawk

final class RepositoryCodeDirectoryViewController: BaseListViewController<NSNumber>,
BaseListViewControllerDataSource,
Expand Down Expand Up @@ -123,7 +124,8 @@ RepositoryBranchUpdatable {
path: path.path
) { [weak self] (result) in
switch result {
case .error:
case .error(let error):
Squawk.show(error: error)
self?.error(animated: trueUnlessReduceMotionEnabled)
case .success(let files):
self?.files = files
Expand Down
4 changes: 3 additions & 1 deletion Classes/Repository/RepositoryOverviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit
import IGListKit
import GitHubAPI
import Squawk

class HackScrollIndicatorInsetsCollectionView: UICollectionView {
override var scrollIndicatorInsets: UIEdgeInsets {
Expand Down Expand Up @@ -97,7 +98,8 @@ RepositoryBranchUpdatable {
self?.update(animated: trueUnlessReduceMotionEnabled)
}
}
case .failure:
case .failure(let error):
Squawk.show(error: error)
self?.error(animated: trueUnlessReduceMotionEnabled)
}
}
Expand Down
15 changes: 13 additions & 2 deletions Local Pods/GitHubAPI/GitHubAPI/ClientError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import Foundation
public enum ClientError: Error {
case unauthorized
case mismatchedInput
case outputNil(Error?)
case network(Error?)
}

extension ClientError: LocalizedError {

public var localizedDescription: String {
switch self {
case .unauthorized:
return NSLocalizedString("You are unauthorized to make this request.", comment: "")
case .mismatchedInput:
return NSLocalizedString("There was an error parsing this response.", comment: "")
}
}

}
8 changes: 4 additions & 4 deletions Local Pods/GitHubAPI/GitHubAPI/Processing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ internal func processResponse<T: Request>(
response: HTTPURLResponse? = nil,
error: Error? = nil
) -> Result<T.ResponseType> {
guard error == nil else {
return .failure(error)
}
guard let input = input as? T.ResponseType.InputType else {
return .failure(ClientError.mismatchedInput)
}
guard error == nil else {
return .failure(ClientError.network(error))
}
do {
let output = try T.ResponseType(input: input, response: response)
return .success(output)
} catch {
return .failure(ClientError.outputNil(error))
return .failure(error)
}
}

Expand Down