Skip to content

Commit e6b6074

Browse files
Merge pull request #1295 from apollographql/add/LocalizedErrors
Add some error descriptions
2 parents 36bc7b6 + fb52d1f commit e6b6074

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

Sources/Apollo/URLSessionClient.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@ import ApolloCore
1313
/// when for background sessions.
1414
open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate {
1515

16-
public enum URLSessionClientError: Error {
16+
public enum URLSessionClientError: Error, LocalizedError {
1717
case noHTTPResponse(request: URLRequest?)
1818
case sessionBecameInvalidWithoutUnderlyingError
1919
case dataForRequestNotFound(request: URLRequest?)
2020
case networkError(data: Data, response: HTTPURLResponse?, underlying: Error)
21+
22+
public var errorDescription: String? {
23+
switch self {
24+
case .noHTTPResponse(let request):
25+
return "The request did not receive an HTTP response. Request: \(String(describing: request))"
26+
case .sessionBecameInvalidWithoutUnderlyingError:
27+
return "The URL session became invalid, but no underlying error was returned."
28+
case .dataForRequestNotFound(let request):
29+
return "URLSessionClient was not able to locate the stored data for request \(String(describing: request))"
30+
case .networkError(_, _, let underlyingError):
31+
return "A network error occurred: \(underlyingError.localizedDescription)"
32+
}
33+
}
2134
}
2235

2336
/// A completion block to be called when the raw task has completed, with the raw information from the session

Sources/ApolloCodegenLib/String+Apollo.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import Foundation
33
import ApolloCore
44
#endif
55

6-
enum ApolloStringError: Error {
6+
enum ApolloStringError: Error, LocalizedError {
77
case expectedSuffixMissing(_ suffix: String)
8+
9+
var errorDescription: String? {
10+
switch self {
11+
case .expectedSuffixMissing(let suffix):
12+
return "Expected \"\(self)\" to have suffix \"\(suffix)\", but it did not. Cannot drop a suffix that doesn't exist!"
13+
}
14+
}
815
}
916

1017
extension ApolloExtension where Base == String {

0 commit comments

Comments
 (0)