Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some error descriptions #1295

Merged
merged 2 commits into from
Jul 7, 2020
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
15 changes: 14 additions & 1 deletion Sources/Apollo/URLSessionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ import ApolloCore
/// when for background sessions.
open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate {

public enum URLSessionClientError: Error {
public enum URLSessionClientError: Error, LocalizedError {
case noHTTPResponse(request: URLRequest?)
case sessionBecameInvalidWithoutUnderlyingError
case dataForRequestNotFound(request: URLRequest?)
case networkError(data: Data, response: HTTPURLResponse?, underlying: Error)

public var errorDescription: String? {
switch self {
case .noHTTPResponse(let request):
return "The request did not receive an HTTP response. Request: \(String(describing: request))"
case .sessionBecameInvalidWithoutUnderlyingError:
return "The URL session became invalid, but no underlying error was returned."
case .dataForRequestNotFound(let request):
return "URLSessionClient was not able to locate the stored data for request \(String(describing: request))"
case .networkError(_, _, let underlyingError):
return "A network error occurred: \(underlyingError.localizedDescription)"
}
}
}

/// A completion block to be called when the raw task has completed, with the raw information from the session
Expand Down
9 changes: 8 additions & 1 deletion Sources/ApolloCodegenLib/String+Apollo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import Foundation
import ApolloCore
#endif

enum ApolloStringError: Error {
enum ApolloStringError: Error, LocalizedError {
case expectedSuffixMissing(_ suffix: String)

var errorDescription: String? {
switch self {
case .expectedSuffixMissing(let suffix):
return "Expected \"\(self)\" to have suffix \"\(suffix)\", but it did not. Cannot drop a suffix that doesn't exist!"
}
}
}

extension ApolloExtension where Base == String {
Expand Down