AFError.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. //
  2. // AFError.swift
  3. //
  4. // Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/)
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. //
  24. import Foundation
  25. /// `AFError` is the error type returned by Alamofire. It encompasses a few different types of errors, each with
  26. /// their own associated reasons.
  27. ///
  28. /// - explicitlyCancelled: Returned when a `Request` is explicitly cancelled.
  29. /// - invalidURL: Returned when a `URLConvertible` type fails to create a valid `URL`.
  30. /// - parameterEncodingFailed: Returned when a parameter encoding object throws an error during the encoding process.
  31. /// - multipartEncodingFailed: Returned when some step in the multipart encoding process fails.
  32. /// - responseValidationFailed: Returned when a `validate()` call fails.
  33. /// - responseSerializationFailed: Returned when a response serializer encounters an error in the serialization process.
  34. /// - certificatePinningFailed: Returned when a response fails certificate pinning.
  35. public enum AFError: Error {
  36. /// The underlying reason the parameter encoding error occurred.
  37. ///
  38. /// - missingURL: The URL request did not have a URL to encode.
  39. /// - jsonEncodingFailed: JSON serialization failed with an underlying system error during the
  40. /// encoding process.
  41. public enum ParameterEncodingFailureReason {
  42. case missingURL
  43. case jsonEncodingFailed(error: Error)
  44. }
  45. /// Underlying reason the parameter encoder error occured.
  46. public enum ParameterEncoderFailureReason {
  47. /// Possible missing components.
  48. public enum RequiredComponent {
  49. /// The `URL` was missing or unable to be extracted from the passed `URLRequest` or during encoding.
  50. case url
  51. /// The `HTTPMethod` could not be extracted from the passed `URLRequest`.
  52. case httpMethod(rawValue: String)
  53. }
  54. /// A `RequiredComponent` was missing during encoding.
  55. case missingRequiredComponent(RequiredComponent)
  56. /// The underlying encoder failed with the associated error.
  57. case encoderFailed(error: Error)
  58. }
  59. /// The underlying reason the multipart encoding error occurred.
  60. ///
  61. /// - bodyPartURLInvalid: The `fileURL` provided for reading an encodable body part isn't a
  62. /// file URL.
  63. /// - bodyPartFilenameInvalid: The filename of the `fileURL` provided has either an empty
  64. /// `lastPathComponent` or `pathExtension.
  65. /// - bodyPartFileNotReachable: The file at the `fileURL` provided was not reachable.
  66. /// - bodyPartFileNotReachableWithError: Attempting to check the reachability of the `fileURL` provided threw
  67. /// an error.
  68. /// - bodyPartFileIsDirectory: The file at the `fileURL` provided is actually a directory.
  69. /// - bodyPartFileSizeNotAvailable: The size of the file at the `fileURL` provided was not returned by
  70. /// the system.
  71. /// - bodyPartFileSizeQueryFailedWithError: The attempt to find the size of the file at the `fileURL` provided
  72. /// threw an error.
  73. /// - bodyPartInputStreamCreationFailed: An `InputStream` could not be created for the provided `fileURL`.
  74. /// - outputStreamCreationFailed: An `OutputStream` could not be created when attempting to write the
  75. /// encoded data to disk.
  76. /// - outputStreamFileAlreadyExists: The encoded body data could not be writtent disk because a file
  77. /// already exists at the provided `fileURL`.
  78. /// - outputStreamURLInvalid: The `fileURL` provided for writing the encoded body data to disk is
  79. /// not a file URL.
  80. /// - outputStreamWriteFailed: The attempt to write the encoded body data to disk failed with an
  81. /// underlying error.
  82. /// - inputStreamReadFailed: The attempt to read an encoded body part `InputStream` failed with
  83. /// underlying system error.
  84. public enum MultipartEncodingFailureReason {
  85. case bodyPartURLInvalid(url: URL)
  86. case bodyPartFilenameInvalid(in: URL)
  87. case bodyPartFileNotReachable(at: URL)
  88. case bodyPartFileNotReachableWithError(atURL: URL, error: Error)
  89. case bodyPartFileIsDirectory(at: URL)
  90. case bodyPartFileSizeNotAvailable(at: URL)
  91. case bodyPartFileSizeQueryFailedWithError(forURL: URL, error: Error)
  92. case bodyPartInputStreamCreationFailed(for: URL)
  93. case outputStreamCreationFailed(for: URL)
  94. case outputStreamFileAlreadyExists(at: URL)
  95. case outputStreamURLInvalid(url: URL)
  96. case outputStreamWriteFailed(error: Error)
  97. case inputStreamReadFailed(error: Error)
  98. }
  99. /// The underlying reason the response validation error occurred.
  100. ///
  101. /// - dataFileNil: The data file containing the server response did not exist.
  102. /// - dataFileReadFailed: The data file containing the server response could not be read.
  103. /// - missingContentType: The response did not contain a `Content-Type` and the `acceptableContentTypes`
  104. /// provided did not contain wildcard type.
  105. /// - unacceptableContentType: The response `Content-Type` did not match any type in the provided
  106. /// `acceptableContentTypes`.
  107. /// - unacceptableStatusCode: The response status code was not acceptable.
  108. public enum ResponseValidationFailureReason {
  109. case dataFileNil
  110. case dataFileReadFailed(at: URL)
  111. case missingContentType(acceptableContentTypes: [String])
  112. case unacceptableContentType(acceptableContentTypes: [String], responseContentType: String)
  113. case unacceptableStatusCode(code: Int)
  114. }
  115. /// The underlying reason the response serialization error occurred.
  116. public enum ResponseSerializationFailureReason {
  117. /// The server response contained no data or the data was zero length.
  118. case inputDataNilOrZeroLength
  119. /// The file containing the server response did not exist.
  120. case inputFileNil
  121. /// The file containing the server response could not be read from the associated `URL`.
  122. case inputFileReadFailed(at: URL)
  123. /// String serialization failed using the provided `String.Encoding`.
  124. case stringSerializationFailed(encoding: String.Encoding)
  125. /// JSON serialization failed with an underlying system error.
  126. case jsonSerializationFailed(error: Error)
  127. /// A `DataDecoder` failed to decode the response due to the associated `Error`.
  128. case decodingFailed(error: Error)
  129. /// Generic serialization failed for an empty response that wasn't type `Empty` but instead the associated type.
  130. case invalidEmptyResponse(type: String)
  131. }
  132. /// Underlying reason a server trust evaluation error occured.
  133. public enum ServerTrustFailureReason {
  134. /// The output of a server trust evaluation.
  135. public struct Output {
  136. /// The host for which the evaluation was performed.
  137. public let host: String
  138. /// The `SecTrust` value which was evaluated.
  139. public let trust: SecTrust
  140. /// The `OSStatus` of evaluation operation.
  141. public let status: OSStatus
  142. /// The result of the evaluation operation.
  143. public let result: SecTrustResultType
  144. /// Creates an `Output` value from the provided values.
  145. init(_ host: String, _ trust: SecTrust, _ status: OSStatus, _ result: SecTrustResultType) {
  146. self.host = host
  147. self.trust = trust
  148. self.status = status
  149. self.result = result
  150. }
  151. }
  152. case noRequiredEvaluator(host: String)
  153. /// No certificates were found with which to perform the trust evaluation.
  154. case noCertificatesFound
  155. /// No public keys were found with which to perform the trust evaluation.
  156. case noPublicKeysFound
  157. /// During evaluation, application of the associated `SecPolicy` failed.
  158. case policyApplicationFailed(trust: SecTrust, policy: SecPolicy, status: OSStatus)
  159. /// During evaluation, setting the associated anchor certificates failed.
  160. case settingAnchorCertificatesFailed(status: OSStatus, certificates: [SecCertificate])
  161. /// During evaluation, creation of the revocation policy failed.
  162. case revocationPolicyCreationFailed
  163. /// Default evaluation failed with the associated `Output`.
  164. case defaultEvaluationFailed(output: Output)
  165. /// Host validation failed with the associated `Output`.
  166. case hostValidationFailed(output: Output)
  167. /// Revocation check failed with the associated `Output` and options.
  168. case revocationCheckFailed(output: Output, options: RevocationTrustEvaluator.Options)
  169. /// Certificate pinning failed.
  170. case certificatePinningFailed(host: String, trust: SecTrust, pinnedCertificates: [SecCertificate], serverCertificates: [SecCertificate])
  171. /// Public key pinning failed.
  172. case publicKeyPinningFailed(host: String, trust: SecTrust, pinnedKeys: [SecKey], serverKeys: [SecKey])
  173. }
  174. case explicitlyCancelled
  175. case invalidURL(url: URLConvertible)
  176. case parameterEncodingFailed(reason: ParameterEncodingFailureReason)
  177. case parameterEncoderFailed(reason: ParameterEncoderFailureReason)
  178. case multipartEncodingFailed(reason: MultipartEncodingFailureReason)
  179. case responseValidationFailed(reason: ResponseValidationFailureReason)
  180. case responseSerializationFailed(reason: ResponseSerializationFailureReason)
  181. case serverTrustEvaluationFailed(reason: ServerTrustFailureReason)
  182. }
  183. extension Error {
  184. /// Returns the instance cast as an `AFError`.
  185. public var asAFError: AFError? {
  186. return self as? AFError
  187. }
  188. }
  189. // MARK: - Error Booleans
  190. extension AFError {
  191. /// Returns whether the `AFError` is an explicitly cancelled error.
  192. public var isExplicitlyCancelledError: Bool {
  193. if case .explicitlyCancelled = self { return true }
  194. return false
  195. }
  196. /// Returns whether the AFError is an invalid URL error.
  197. public var isInvalidURLError: Bool {
  198. if case .invalidURL = self { return true }
  199. return false
  200. }
  201. /// Returns whether the AFError is a parameter encoding error. When `true`, the `underlyingError` property will
  202. /// contain the associated value.
  203. public var isParameterEncodingError: Bool {
  204. if case .parameterEncodingFailed = self { return true }
  205. return false
  206. }
  207. /// Returns whether the instance is a parameter encoder error.
  208. public var isParameterEncoderError: Bool {
  209. if case .parameterEncoderFailed = self { return true }
  210. return false
  211. }
  212. /// Returns whether the AFError is a multipart encoding error. When `true`, the `url` and `underlyingError` properties
  213. /// will contain the associated values.
  214. public var isMultipartEncodingError: Bool {
  215. if case .multipartEncodingFailed = self { return true }
  216. return false
  217. }
  218. /// Returns whether the `AFError` is a response validation error. When `true`, the `acceptableContentTypes`,
  219. /// `responseContentType`, and `responseCode` properties will contain the associated values.
  220. public var isResponseValidationError: Bool {
  221. if case .responseValidationFailed = self { return true }
  222. return false
  223. }
  224. /// Returns whether the `AFError` is a response serialization error. When `true`, the `failedStringEncoding` and
  225. /// `underlyingError` properties will contain the associated values.
  226. public var isResponseSerializationError: Bool {
  227. if case .responseSerializationFailed = self { return true }
  228. return false
  229. }
  230. /// Returns whether the `AFError` is a server trust evaluation error.
  231. public var isServerTrustEvaluationError: Bool {
  232. if case .serverTrustEvaluationFailed = self { return true }
  233. return false
  234. }
  235. }
  236. // MARK: - Convenience Properties
  237. extension AFError {
  238. /// The `URLConvertible` associated with the error.
  239. public var urlConvertible: URLConvertible? {
  240. switch self {
  241. case .invalidURL(let url):
  242. return url
  243. default:
  244. return nil
  245. }
  246. }
  247. /// The `URL` associated with the error.
  248. public var url: URL? {
  249. switch self {
  250. case .multipartEncodingFailed(let reason):
  251. return reason.url
  252. default:
  253. return nil
  254. }
  255. }
  256. /// The `Error` returned by a system framework associated with a `.parameterEncodingFailed`,
  257. /// `.parameterEncoderFailed`, `.multipartEncodingFailed` or `.responseSerializationFailed` error.
  258. public var underlyingError: Error? {
  259. switch self {
  260. case .parameterEncodingFailed(let reason):
  261. return reason.underlyingError
  262. case .parameterEncoderFailed(let reason):
  263. return reason.underlyingError
  264. case .multipartEncodingFailed(let reason):
  265. return reason.underlyingError
  266. case .responseSerializationFailed(let reason):
  267. return reason.underlyingError
  268. default:
  269. return nil
  270. }
  271. }
  272. /// The acceptable `Content-Type`s of a `.responseValidationFailed` error.
  273. public var acceptableContentTypes: [String]? {
  274. switch self {
  275. case .responseValidationFailed(let reason):
  276. return reason.acceptableContentTypes
  277. default:
  278. return nil
  279. }
  280. }
  281. /// The response `Content-Type` of a `.responseValidationFailed` error.
  282. public var responseContentType: String? {
  283. switch self {
  284. case .responseValidationFailed(let reason):
  285. return reason.responseContentType
  286. default:
  287. return nil
  288. }
  289. }
  290. /// The response code of a `.responseValidationFailed` error.
  291. public var responseCode: Int? {
  292. switch self {
  293. case .responseValidationFailed(let reason):
  294. return reason.responseCode
  295. default:
  296. return nil
  297. }
  298. }
  299. /// The `String.Encoding` associated with a failed `.stringResponse()` call.
  300. public var failedStringEncoding: String.Encoding? {
  301. switch self {
  302. case .responseSerializationFailed(let reason):
  303. return reason.failedStringEncoding
  304. default:
  305. return nil
  306. }
  307. }
  308. }
  309. extension AFError.ParameterEncodingFailureReason {
  310. var underlyingError: Error? {
  311. switch self {
  312. case .jsonEncodingFailed(let error):
  313. return error
  314. default:
  315. return nil
  316. }
  317. }
  318. }
  319. extension AFError.ParameterEncoderFailureReason {
  320. var underlyingError: Error? {
  321. switch self {
  322. case .encoderFailed(let error):
  323. return error
  324. default:
  325. return nil
  326. }
  327. }
  328. }
  329. extension AFError.MultipartEncodingFailureReason {
  330. var url: URL? {
  331. switch self {
  332. case .bodyPartURLInvalid(let url), .bodyPartFilenameInvalid(let url), .bodyPartFileNotReachable(let url),
  333. .bodyPartFileIsDirectory(let url), .bodyPartFileSizeNotAvailable(let url),
  334. .bodyPartInputStreamCreationFailed(let url), .outputStreamCreationFailed(let url),
  335. .outputStreamFileAlreadyExists(let url), .outputStreamURLInvalid(let url),
  336. .bodyPartFileNotReachableWithError(let url, _), .bodyPartFileSizeQueryFailedWithError(let url, _):
  337. return url
  338. default:
  339. return nil
  340. }
  341. }
  342. var underlyingError: Error? {
  343. switch self {
  344. case .bodyPartFileNotReachableWithError(_, let error), .bodyPartFileSizeQueryFailedWithError(_, let error),
  345. .outputStreamWriteFailed(let error), .inputStreamReadFailed(let error):
  346. return error
  347. default:
  348. return nil
  349. }
  350. }
  351. }
  352. extension AFError.ResponseValidationFailureReason {
  353. var acceptableContentTypes: [String]? {
  354. switch self {
  355. case .missingContentType(let types), .unacceptableContentType(let types, _):
  356. return types
  357. default:
  358. return nil
  359. }
  360. }
  361. var responseContentType: String? {
  362. switch self {
  363. case .unacceptableContentType(_, let responseType):
  364. return responseType
  365. default:
  366. return nil
  367. }
  368. }
  369. var responseCode: Int? {
  370. switch self {
  371. case .unacceptableStatusCode(let code):
  372. return code
  373. default:
  374. return nil
  375. }
  376. }
  377. }
  378. extension AFError.ResponseSerializationFailureReason {
  379. var failedStringEncoding: String.Encoding? {
  380. switch self {
  381. case .stringSerializationFailed(let encoding):
  382. return encoding
  383. default:
  384. return nil
  385. }
  386. }
  387. var underlyingError: Error? {
  388. switch self {
  389. case .jsonSerializationFailed(let error):
  390. return error
  391. default:
  392. return nil
  393. }
  394. }
  395. }
  396. extension AFError.ServerTrustFailureReason {
  397. var output: AFError.ServerTrustFailureReason.Output? {
  398. switch self {
  399. case let .defaultEvaluationFailed(output),
  400. let .hostValidationFailed(output),
  401. let .revocationCheckFailed(output, _):
  402. return output
  403. default: return nil
  404. }
  405. }
  406. }
  407. // MARK: - Error Descriptions
  408. extension AFError: LocalizedError {
  409. public var errorDescription: String? {
  410. switch self {
  411. case .explicitlyCancelled:
  412. return "Request explicitly cancelled."
  413. case .invalidURL(let url):
  414. return "URL is not valid: \(url)"
  415. case .parameterEncodingFailed(let reason):
  416. return reason.localizedDescription
  417. case .parameterEncoderFailed(let reason):
  418. return reason.localizedDescription
  419. case .multipartEncodingFailed(let reason):
  420. return reason.localizedDescription
  421. case .responseValidationFailed(let reason):
  422. return reason.localizedDescription
  423. case .responseSerializationFailed(let reason):
  424. return reason.localizedDescription
  425. case .serverTrustEvaluationFailed:
  426. return "Server trust evaluation failed."
  427. }
  428. }
  429. }
  430. extension AFError.ParameterEncodingFailureReason {
  431. var localizedDescription: String {
  432. switch self {
  433. case .missingURL:
  434. return "URL request to encode was missing a URL"
  435. case .jsonEncodingFailed(let error):
  436. return "JSON could not be encoded because of error:\n\(error.localizedDescription)"
  437. }
  438. }
  439. }
  440. extension AFError.ParameterEncoderFailureReason {
  441. var localizedDescription: String {
  442. switch self {
  443. case .missingRequiredComponent(let component):
  444. return "Encoding failed due to a missing request component: \(component)"
  445. case .encoderFailed(let error):
  446. return "The underlying encoder failed with the error: \(error)"
  447. }
  448. }
  449. }
  450. extension AFError.MultipartEncodingFailureReason {
  451. var localizedDescription: String {
  452. switch self {
  453. case .bodyPartURLInvalid(let url):
  454. return "The URL provided is not a file URL: \(url)"
  455. case .bodyPartFilenameInvalid(let url):
  456. return "The URL provided does not have a valid filename: \(url)"
  457. case .bodyPartFileNotReachable(let url):
  458. return "The URL provided is not reachable: \(url)"
  459. case .bodyPartFileNotReachableWithError(let url, let error):
  460. return (
  461. "The system returned an error while checking the provided URL for " +
  462. "reachability.\nURL: \(url)\nError: \(error)"
  463. )
  464. case .bodyPartFileIsDirectory(let url):
  465. return "The URL provided is a directory: \(url)"
  466. case .bodyPartFileSizeNotAvailable(let url):
  467. return "Could not fetch the file size from the provided URL: \(url)"
  468. case .bodyPartFileSizeQueryFailedWithError(let url, let error):
  469. return (
  470. "The system returned an error while attempting to fetch the file size from the " +
  471. "provided URL.\nURL: \(url)\nError: \(error)"
  472. )
  473. case .bodyPartInputStreamCreationFailed(let url):
  474. return "Failed to create an InputStream for the provided URL: \(url)"
  475. case .outputStreamCreationFailed(let url):
  476. return "Failed to create an OutputStream for URL: \(url)"
  477. case .outputStreamFileAlreadyExists(let url):
  478. return "A file already exists at the provided URL: \(url)"
  479. case .outputStreamURLInvalid(let url):
  480. return "The provided OutputStream URL is invalid: \(url)"
  481. case .outputStreamWriteFailed(let error):
  482. return "OutputStream write failed with error: \(error)"
  483. case .inputStreamReadFailed(let error):
  484. return "InputStream read failed with error: \(error)"
  485. }
  486. }
  487. }
  488. extension AFError.ResponseSerializationFailureReason {
  489. var localizedDescription: String {
  490. switch self {
  491. case .inputDataNilOrZeroLength:
  492. return "Response could not be serialized, input data was nil or zero length."
  493. case .inputFileNil:
  494. return "Response could not be serialized, input file was nil."
  495. case .inputFileReadFailed(let url):
  496. return "Response could not be serialized, input file could not be read: \(url)."
  497. case .stringSerializationFailed(let encoding):
  498. return "String could not be serialized with encoding: \(encoding)."
  499. case .jsonSerializationFailed(let error):
  500. return "JSON could not be serialized because of error:\n\(error.localizedDescription)"
  501. case .invalidEmptyResponse(let type):
  502. return "Empty response could not be serialized to type: \(type). Use Empty as the expected type for such responses."
  503. case .decodingFailed(let error):
  504. return "Response could not be decoded because of error:\n\(error.localizedDescription)"
  505. }
  506. }
  507. }
  508. extension AFError.ResponseValidationFailureReason {
  509. var localizedDescription: String {
  510. switch self {
  511. case .dataFileNil:
  512. return "Response could not be validated, data file was nil."
  513. case .dataFileReadFailed(let url):
  514. return "Response could not be validated, data file could not be read: \(url)."
  515. case .missingContentType(let types):
  516. return (
  517. "Response Content-Type was missing and acceptable content types " +
  518. "(\(types.joined(separator: ","))) do not match \"*/*\"."
  519. )
  520. case .unacceptableContentType(let acceptableTypes, let responseType):
  521. return (
  522. "Response Content-Type \"\(responseType)\" does not match any acceptable types: " +
  523. "\(acceptableTypes.joined(separator: ","))."
  524. )
  525. case .unacceptableStatusCode(let code):
  526. return "Response status code was unacceptable: \(code)."
  527. }
  528. }
  529. }
  530. extension AFError.ServerTrustFailureReason {
  531. var localizedDescription: String {
  532. switch self {
  533. case let .noRequiredEvaluator(host):
  534. return "A ServerTrustEvaluating value is required for host \(host) but none was found."
  535. case .noCertificatesFound:
  536. return "No certificates were found or provided for evaluation."
  537. case .noPublicKeysFound:
  538. return "No public keys were found or provided for evaluation."
  539. case .policyApplicationFailed:
  540. return "Attempting to set a SecPolicy failed."
  541. case .settingAnchorCertificatesFailed:
  542. return "Attempting to set the provided certificates as anchor certificates failed."
  543. case .revocationPolicyCreationFailed:
  544. return "Attempting to create a revocation policy failed."
  545. case let .defaultEvaluationFailed(output):
  546. return "Default evaluation failed for host \(output.host)."
  547. case let .hostValidationFailed(output):
  548. return "Host validation failed for host \(output.host)."
  549. case let .revocationCheckFailed(output, _):
  550. return "Revocation check failed for host \(output.host)."
  551. case let .certificatePinningFailed(host, _, _, _):
  552. return "Certificate pinning failed for host \(host)."
  553. case let .publicKeyPinningFailed(host, _, _, _):
  554. return "Public key pinning failed for host \(host)."
  555. }
  556. }
  557. }