|
|
@@ -185,6 +185,8 @@ public enum AFError: Error {
|
|
|
case publicKeyPinningFailed(host: String, trust: SecTrust, pinnedKeys: [SecKey], serverKeys: [SecKey])
|
|
|
}
|
|
|
|
|
|
+ case sessionDeinitialized
|
|
|
+ case sessionInvalidated(error: Error?)
|
|
|
case explicitlyCancelled
|
|
|
case invalidURL(url: URLConvertible)
|
|
|
case parameterEncodingFailed(reason: ParameterEncodingFailureReason)
|
|
|
@@ -207,66 +209,79 @@ extension Error {
|
|
|
// MARK: - Error Booleans
|
|
|
|
|
|
extension AFError {
|
|
|
- /// Returns whether the `AFError` is an explicitly cancelled error.
|
|
|
+ // Returns whether the instance is `.sessionDeinitialized`.
|
|
|
+ public var isSessionDeinitializedError: Bool {
|
|
|
+ if case .sessionDeinitialized = self { return true }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ // Returns whether the instance is `.sessionInvalidated`.
|
|
|
+ public var isSessionInvalidatedError: Bool {
|
|
|
+ if case .sessionInvalidated = self { return true }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Returns whether the instance is `.explicitlyCancelled`.
|
|
|
public var isExplicitlyCancelledError: Bool {
|
|
|
if case .explicitlyCancelled = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the AFError is an invalid URL error.
|
|
|
+ /// Returns whether the instance is `.invalidURL`.
|
|
|
public var isInvalidURLError: Bool {
|
|
|
if case .invalidURL = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the AFError is a parameter encoding error. When `true`, the `underlyingError` property will
|
|
|
+ /// Returns whether the instance is `.parameterEncodingFailed`. When `true`, the `underlyingError` property will
|
|
|
/// contain the associated value.
|
|
|
public var isParameterEncodingError: Bool {
|
|
|
if case .parameterEncodingFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the instance is a parameter encoder error.
|
|
|
+ /// Returns whether the instance is `.parameterEncoderFailed`. When `true`, the `underlyingError` property will
|
|
|
+ // contain the associated value.
|
|
|
public var isParameterEncoderError: Bool {
|
|
|
if case .parameterEncoderFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the AFError is a multipart encoding error. When `true`, the `url` and `underlyingError` properties
|
|
|
- /// will contain the associated values.
|
|
|
+ /// Returns whether the instance is `.multipartEncodingFailed`. When `true`, the `url` and `underlyingError`
|
|
|
+ /// properties will contain the associated values.
|
|
|
public var isMultipartEncodingError: Bool {
|
|
|
if case .multipartEncodingFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the AFError is a request adaptation error. When `true`, the `underlyingError` property will
|
|
|
+ /// Returns whether the instance is `.requestAdaptationFailed`. When `true`, the `underlyingError` property will
|
|
|
/// contain the associated value.
|
|
|
public var isRequestAdaptationError: Bool {
|
|
|
if case .requestAdaptationFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the `AFError` is a response validation error. When `true`, the `acceptableContentTypes`,
|
|
|
+ /// Returns whether the instance is `.responseValidationFailed`. When `true`, the `acceptableContentTypes`,
|
|
|
/// `responseContentType`, and `responseCode` properties will contain the associated values.
|
|
|
public var isResponseValidationError: Bool {
|
|
|
if case .responseValidationFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the `AFError` is a response serialization error. When `true`, the `failedStringEncoding` and
|
|
|
+ /// Returns whether the instance is `.responseSerializationFailed`. When `true`, the `failedStringEncoding` and
|
|
|
/// `underlyingError` properties will contain the associated values.
|
|
|
public var isResponseSerializationError: Bool {
|
|
|
if case .responseSerializationFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the `AFError` is a server trust evaluation error.
|
|
|
+ /// Returns whether the instance is `.serverTrustEvaluationFailed`.
|
|
|
public var isServerTrustEvaluationError: Bool {
|
|
|
if case .serverTrustEvaluationFailed = self { return true }
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- /// Returns whether the AFError is a request retry error. When `true`, the `underlyingError` property will
|
|
|
+ /// Returns whether the instance is `requestRetryFailed`. When `true`, the `underlyingError` property will
|
|
|
/// contain the associated value.
|
|
|
public var isRequestRetryError: Bool {
|
|
|
if case .requestRetryFailed = self { return true }
|
|
|
@@ -297,11 +312,13 @@ extension AFError {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// The underlying `Error` responsible for generating the failure associated with `.parameterEncodingFailed`,
|
|
|
- /// `.parameterEncoderFailed`, `.multipartEncodingFailed`, `.requestAdaptationFailed`,
|
|
|
+ /// The underlying `Error` responsible for generating the failure associated with `.sessionInvalidated`,
|
|
|
+ /// `.parameterEncodingFailed`, `.parameterEncoderFailed`, `.multipartEncodingFailed`, `.requestAdaptationFailed`,
|
|
|
/// `.responseSerializationFailed`, `.requestRetryFailed` errors.
|
|
|
public var underlyingError: Error? {
|
|
|
switch self {
|
|
|
+ case .sessionInvalidated(let error):
|
|
|
+ return error
|
|
|
case .parameterEncodingFailed(let reason):
|
|
|
return reason.underlyingError
|
|
|
case .parameterEncoderFailed(let reason):
|
|
|
@@ -473,6 +490,13 @@ extension AFError.ServerTrustFailureReason {
|
|
|
extension AFError: LocalizedError {
|
|
|
public var errorDescription: String? {
|
|
|
switch self {
|
|
|
+ case .sessionDeinitialized:
|
|
|
+ return """
|
|
|
+ Session was invalidated without error, so it was likely deinitialized unexpectedly. \
|
|
|
+ Be sure to retain a reference to your Session for the duration of your requests.
|
|
|
+ """
|
|
|
+ case .sessionInvalidated(let error):
|
|
|
+ return "Session was invalidated with error: \(error?.localizedDescription ?? "No description.")"
|
|
|
case .explicitlyCancelled:
|
|
|
return "Request explicitly cancelled."
|
|
|
case .invalidURL(let url):
|
|
|
@@ -492,8 +516,10 @@ extension AFError: LocalizedError {
|
|
|
case .serverTrustEvaluationFailed:
|
|
|
return "Server trust evaluation failed."
|
|
|
case .requestRetryFailed(let retryError, let originalError):
|
|
|
- return "Request retry failed with retry error: \(retryError.localizedDescription), " +
|
|
|
- "original error: \(originalError.localizedDescription)"
|
|
|
+ return """
|
|
|
+ Request retry failed with retry error: \(retryError.localizedDescription), \
|
|
|
+ original error: \(originalError.localizedDescription)
|
|
|
+ """
|
|
|
}
|
|
|
}
|
|
|
}
|