AFError.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. ///
  117. /// - inputDataNil: The server response contained no data.
  118. /// - inputDataNilOrZeroLength: The server response contained no data or the data was zero length.
  119. /// - inputFileNil: The file containing the server response did not exist.
  120. /// - inputFileReadFailed: The file containing the server response could not be read.
  121. /// - stringSerializationFailed: String serialization failed using the provided `String.Encoding`.
  122. /// - jsonSerializationFailed: JSON serialization failed with an underlying system error.
  123. /// - invalidEmptyResponse: Generic serialization failed for an empty response that wasn't type `Empty`.
  124. public enum ResponseSerializationFailureReason {
  125. case inputDataNilOrZeroLength
  126. case inputFileNil
  127. case inputFileReadFailed(at: URL)
  128. case stringSerializationFailed(encoding: String.Encoding)
  129. case jsonSerializationFailed(error: Error)
  130. case invalidEmptyResponse(type: String)
  131. case jsonDecodingFailed(error: Error)
  132. }
  133. /// Underlying reason a server trust evaluation error occured.
  134. public enum ServerTrustFailureReason {
  135. /// The output of a server trust evaluation.
  136. public struct Output {
  137. /// The host for which the evaluation was performed.
  138. public let host: String
  139. /// The `SecTrust` value which was evaluated.
  140. public let trust: SecTrust
  141. /// The `OSStatus` of evaluation operation.
  142. public let status: OSStatus
  143. /// The result of the evaluation operation.
  144. public let result: SecTrustResultType
  145. /// Creates an `Output` value from the provided values.
  146. init(_ host: String, _ trust: SecTrust, _ status: OSStatus, _ result: SecTrustResultType) {
  147. self.host = host
  148. self.trust = trust
  149. self.status = status
  150. self.result = result
  151. }
  152. }
  153. case noRequiredEvaluator(host: String)
  154. /// No certificates were found with which to perform the trust evaluation.
  155. case noCertificatesFound
  156. /// No public keys were found with which to perform the trust evaluation.
  157. case noPublicKeysFound
  158. /// During evaluation, application of the associated `SecPolicy` failed.
  159. case policyApplicationFailed(trust: SecTrust, policy: SecPolicy, status: OSStatus)
  160. /// During evaluation, setting the associated anchor certificates failed.
  161. case settingAnchorCertificatesFailed(status: OSStatus, certificates: [SecCertificate])
  162. /// During evaluation, creation of the revocation policy failed.
  163. case revocationPolicyCreationFailed
  164. /// Default evaluation failed with the associated `Output`.
  165. case defaultEvaluationFailed(output: Output)
  166. /// Host validation failed with the associated `Output`.
  167. case hostValidationFailed(output: Output)
  168. /// Revocation check failed with the associated `Output` and options.
  169. case revocationCheckFailed(output: Output, options: RevocationTrustEvaluator.Options)
  170. /// Certificate pinning failed.
  171. case certificatePinningFailed(host: String, trust: SecTrust, pinnedCertificates: [SecCertificate], serverCertificates: [SecCertificate])
  172. /// Public key pinning failed.
  173. case publicKeyPinningFailed(host: String, trust: SecTrust, pinnedKeys: [SecKey], serverKeys: [SecKey])
  174. }
  175. case explicitlyCancelled
  176. case invalidURL(url: URLConvertible)
  177. case parameterEncodingFailed(reason: ParameterEncodingFailureReason)
  178. case parameterEncoderFailed(reason: ParameterEncoderFailureReason)
  179. case multipartEncodingFailed(reason: MultipartEncodingFailureReason)
  180. case responseValidationFailed(reason: ResponseValidationFailureReason)
  181. case responseSerializationFailed(reason: ResponseSerializationFailureReason)
  182. case serverTrustEvaluationFailed(reason: ServerTrustFailureReason)
  183. }
  184. extension Error {
  185. /// Returns the instance cast as an `AFError`.
  186. public var asAFError: AFError? {
  187. return self as? AFError
  188. }
  189. }
  190. // MARK: - Error Booleans
  191. extension AFError {
  192. /// Returns whether the `AFError` is an explicitly cancelled error.
  193. public var isExplicitlyCancelledError: Bool {
  194. if case .explicitlyCancelled = self { return true }
  195. return false
  196. }
  197. /// Returns whether the AFError is an invalid URL error.
  198. public var isInvalidURLError: Bool {
  199. if case .invalidURL = self { return true }
  200. return false
  201. }
  202. /// Returns whether the AFError is a parameter encoding error. When `true`, the `underlyingError` property will
  203. /// contain the associated value.
  204. public var isParameterEncodingError: Bool {
  205. if case .parameterEncodingFailed = self { return true }
  206. return false
  207. }
  208. /// Returns whether the instance is a parameter encoder error.
  209. public var isParameterEncoderError: Bool {
  210. if case .parameterEncoderFailed = self { return true }
  211. return false
  212. }
  213. /// Returns whether the AFError is a multipart encoding error. When `true`, the `url` and `underlyingError` properties
  214. /// will contain the associated values.
  215. public var isMultipartEncodingError: Bool {
  216. if case .multipartEncodingFailed = self { return true }
  217. return false
  218. }
  219. /// Returns whether the `AFError` is a response validation error. When `true`, the `acceptableContentTypes`,
  220. /// `responseContentType`, and `responseCode` properties will contain the associated values.
  221. public var isResponseValidationError: Bool {
  222. if case .responseValidationFailed = self { return true }
  223. return false
  224. }
  225. /// Returns whether the `AFError` is a response serialization error. When `true`, the `failedStringEncoding` and
  226. /// `underlyingError` properties will contain the associated values.
  227. public var isResponseSerializationError: Bool {
  228. if case .responseSerializationFailed = self { return true }
  229. return false
  230. }
  231. /// Returns whether the `AFError` is a server trust evaluation error.
  232. public var isServerTrustEvaluationError: Bool {
  233. if case .serverTrustEvaluationFailed = self { return true }
  234. return false
  235. }
  236. }
  237. // MARK: - Convenience Properties
  238. extension AFError {
  239. /// The `URLConvertible` associated with the error.
  240. public var urlConvertible: URLConvertible? {
  241. switch self {
  242. case .invalidURL(let url):
  243. return url
  244. default:
  245. return nil
  246. }
  247. }
  248. /// The `URL` associated with the error.
  249. public var url: URL? {
  250. switch self {
  251. case .multipartEncodingFailed(let reason):
  252. return reason.url
  253. default:
  254. return nil
  255. }
  256. }
  257. /// The `Error` returned by a system framework associated with a `.parameterEncodingFailed`,
  258. /// `.parameterEncoderFailed`, `.multipartEncodingFailed` or `.responseSerializationFailed` error.
  259. public var underlyingError: Error? {
  260. switch self {
  261. case .parameterEncodingFailed(let reason):
  262. return reason.underlyingError
  263. case .parameterEncoderFailed(let reason):
  264. return reason.underlyingError
  265. case .multipartEncodingFailed(let reason):
  266. return reason.underlyingError
  267. case .responseSerializationFailed(let reason):
  268. return reason.underlyingError
  269. default:
  270. return nil
  271. }
  272. }
  273. /// The acceptable `Content-Type`s of a `.responseValidationFailed` error.
  274. public var acceptableContentTypes: [String]? {
  275. switch self {
  276. case .responseValidationFailed(let reason):
  277. return reason.acceptableContentTypes
  278. default:
  279. return nil
  280. }
  281. }
  282. /// The response `Content-Type` of a `.responseValidationFailed` error.
  283. public var responseContentType: String? {
  284. switch self {
  285. case .responseValidationFailed(let reason):
  286. return reason.responseContentType
  287. default:
  288. return nil
  289. }
  290. }
  291. /// The response code of a `.responseValidationFailed` error.
  292. public var responseCode: Int? {
  293. switch self {
  294. case .responseValidationFailed(let reason):
  295. return reason.responseCode
  296. default:
  297. return nil
  298. }
  299. }
  300. /// The `String.Encoding` associated with a failed `.stringResponse()` call.
  301. public var failedStringEncoding: String.Encoding? {
  302. switch self {
  303. case .responseSerializationFailed(let reason):
  304. return reason.failedStringEncoding
  305. default:
  306. return nil
  307. }
  308. }
  309. }
  310. extension AFError.ParameterEncodingFailureReason {
  311. var underlyingError: Error? {
  312. switch self {
  313. case .jsonEncodingFailed(let error):
  314. return error
  315. default:
  316. return nil
  317. }
  318. }
  319. }
  320. extension AFError.ParameterEncoderFailureReason {
  321. var underlyingError: Error? {
  322. switch self {
  323. case .encoderFailed(let error):
  324. return error
  325. default:
  326. return nil
  327. }
  328. }
  329. }
  330. extension AFError.MultipartEncodingFailureReason {
  331. var url: URL? {
  332. switch self {
  333. case .bodyPartURLInvalid(let url), .bodyPartFilenameInvalid(let url), .bodyPartFileNotReachable(let url),
  334. .bodyPartFileIsDirectory(let url), .bodyPartFileSizeNotAvailable(let url),
  335. .bodyPartInputStreamCreationFailed(let url), .outputStreamCreationFailed(let url),
  336. .outputStreamFileAlreadyExists(let url), .outputStreamURLInvalid(let url),
  337. .bodyPartFileNotReachableWithError(let url, _), .bodyPartFileSizeQueryFailedWithError(let url, _):
  338. return url
  339. default:
  340. return nil
  341. }
  342. }
  343. var underlyingError: Error? {
  344. switch self {
  345. case .bodyPartFileNotReachableWithError(_, let error), .bodyPartFileSizeQueryFailedWithError(_, let error),
  346. .outputStreamWriteFailed(let error), .inputStreamReadFailed(let error):
  347. return error
  348. default:
  349. return nil
  350. }
  351. }
  352. }
  353. extension AFError.ResponseValidationFailureReason {
  354. var acceptableContentTypes: [String]? {
  355. switch self {
  356. case .missingContentType(let types), .unacceptableContentType(let types, _):
  357. return types
  358. default:
  359. return nil
  360. }
  361. }
  362. var responseContentType: String? {
  363. switch self {
  364. case .unacceptableContentType(_, let responseType):
  365. return responseType
  366. default:
  367. return nil
  368. }
  369. }
  370. var responseCode: Int? {
  371. switch self {
  372. case .unacceptableStatusCode(let code):
  373. return code
  374. default:
  375. return nil
  376. }
  377. }
  378. }
  379. extension AFError.ResponseSerializationFailureReason {
  380. var failedStringEncoding: String.Encoding? {
  381. switch self {
  382. case .stringSerializationFailed(let encoding):
  383. return encoding
  384. default:
  385. return nil
  386. }
  387. }
  388. var underlyingError: Error? {
  389. switch self {
  390. case .jsonSerializationFailed(let error):
  391. return error
  392. default:
  393. return nil
  394. }
  395. }
  396. }
  397. extension AFError.ServerTrustFailureReason {
  398. var output: AFError.ServerTrustFailureReason.Output? {
  399. switch self {
  400. case let .defaultEvaluationFailed(output),
  401. let .hostValidationFailed(output),
  402. let .revocationCheckFailed(output, _):
  403. return output
  404. default: return nil
  405. }
  406. }
  407. }
  408. // MARK: - Error Descriptions
  409. extension AFError: LocalizedError {
  410. public var errorDescription: String? {
  411. switch self {
  412. case .explicitlyCancelled:
  413. return "Request explicitly cancelled."
  414. case .invalidURL(let url):
  415. return "URL is not valid: \(url)"
  416. case .parameterEncodingFailed(let reason):
  417. return reason.localizedDescription
  418. case .parameterEncoderFailed(let reason):
  419. return reason.localizedDescription
  420. case .multipartEncodingFailed(let reason):
  421. return reason.localizedDescription
  422. case .responseValidationFailed(let reason):
  423. return reason.localizedDescription
  424. case .responseSerializationFailed(let reason):
  425. return reason.localizedDescription
  426. case .serverTrustEvaluationFailed:
  427. return "Server trust evaluation failed."
  428. }
  429. }
  430. }
  431. extension AFError.ParameterEncodingFailureReason {
  432. var localizedDescription: String {
  433. switch self {
  434. case .missingURL:
  435. return "URL request to encode was missing a URL"
  436. case .jsonEncodingFailed(let error):
  437. return "JSON could not be encoded because of error:\n\(error.localizedDescription)"
  438. }
  439. }
  440. }
  441. extension AFError.ParameterEncoderFailureReason {
  442. var localizedDescription: String {
  443. switch self {
  444. case .missingRequiredComponent(let component):
  445. return "Encoding failed due to a missing request component: \(component)"
  446. case .encoderFailed(let error):
  447. return "The underlying encoder failed with the error: \(error)"
  448. }
  449. }
  450. }
  451. extension AFError.MultipartEncodingFailureReason {
  452. var localizedDescription: String {
  453. switch self {
  454. case .bodyPartURLInvalid(let url):
  455. return "The URL provided is not a file URL: \(url)"
  456. case .bodyPartFilenameInvalid(let url):
  457. return "The URL provided does not have a valid filename: \(url)"
  458. case .bodyPartFileNotReachable(let url):
  459. return "The URL provided is not reachable: \(url)"
  460. case .bodyPartFileNotReachableWithError(let url, let error):
  461. return (
  462. "The system returned an error while checking the provided URL for " +
  463. "reachability.\nURL: \(url)\nError: \(error)"
  464. )
  465. case .bodyPartFileIsDirectory(let url):
  466. return "The URL provided is a directory: \(url)"
  467. case .bodyPartFileSizeNotAvailable(let url):
  468. return "Could not fetch the file size from the provided URL: \(url)"
  469. case .bodyPartFileSizeQueryFailedWithError(let url, let error):
  470. return (
  471. "The system returned an error while attempting to fetch the file size from the " +
  472. "provided URL.\nURL: \(url)\nError: \(error)"
  473. )
  474. case .bodyPartInputStreamCreationFailed(let url):
  475. return "Failed to create an InputStream for the provided URL: \(url)"
  476. case .outputStreamCreationFailed(let url):
  477. return "Failed to create an OutputStream for URL: \(url)"
  478. case .outputStreamFileAlreadyExists(let url):
  479. return "A file already exists at the provided URL: \(url)"
  480. case .outputStreamURLInvalid(let url):
  481. return "The provided OutputStream URL is invalid: \(url)"
  482. case .outputStreamWriteFailed(let error):
  483. return "OutputStream write failed with error: \(error)"
  484. case .inputStreamReadFailed(let error):
  485. return "InputStream read failed with error: \(error)"
  486. }
  487. }
  488. }
  489. extension AFError.ResponseSerializationFailureReason {
  490. var localizedDescription: String {
  491. switch self {
  492. case .inputDataNilOrZeroLength:
  493. return "Response could not be serialized, input data was nil or zero length."
  494. case .inputFileNil:
  495. return "Response could not be serialized, input file was nil."
  496. case .inputFileReadFailed(let url):
  497. return "Response could not be serialized, input file could not be read: \(url)."
  498. case .stringSerializationFailed(let encoding):
  499. return "String could not be serialized with encoding: \(encoding)."
  500. case .jsonSerializationFailed(let error):
  501. return "JSON could not be serialized because of error:\n\(error.localizedDescription)"
  502. case .invalidEmptyResponse(let type):
  503. return "Empty response could not be serialized to type: \(type). Use Empty as the expected type for such responses."
  504. case .jsonDecodingFailed(let error):
  505. return "JSON could not be decoded because of error:\n\(error.localizedDescription)"
  506. }
  507. }
  508. }
  509. extension AFError.ResponseValidationFailureReason {
  510. var localizedDescription: String {
  511. switch self {
  512. case .dataFileNil:
  513. return "Response could not be validated, data file was nil."
  514. case .dataFileReadFailed(let url):
  515. return "Response could not be validated, data file could not be read: \(url)."
  516. case .missingContentType(let types):
  517. return (
  518. "Response Content-Type was missing and acceptable content types " +
  519. "(\(types.joined(separator: ","))) do not match \"*/*\"."
  520. )
  521. case .unacceptableContentType(let acceptableTypes, let responseType):
  522. return (
  523. "Response Content-Type \"\(responseType)\" does not match any acceptable types: " +
  524. "\(acceptableTypes.joined(separator: ","))."
  525. )
  526. case .unacceptableStatusCode(let code):
  527. return "Response status code was unacceptable: \(code)."
  528. }
  529. }
  530. }
  531. extension AFError.ServerTrustFailureReason {
  532. var localizedDescription: String {
  533. switch self {
  534. case let .noRequiredEvaluator(host):
  535. return "A ServerTrustEvaluating value is required for host \(host) but none was found."
  536. case .noCertificatesFound:
  537. return "No certificates were found or provided for evaluation."
  538. case .noPublicKeysFound:
  539. return "No public keys were found or provided for evaluation."
  540. case .policyApplicationFailed:
  541. return "Attempting to set a SecPolicy failed."
  542. case .settingAnchorCertificatesFailed:
  543. return "Attempting to set the provided certificates as anchor certificates failed."
  544. case .revocationPolicyCreationFailed:
  545. return "Attempting to create a revocation policy failed."
  546. case let .defaultEvaluationFailed(output):
  547. return "Default evaluation failed for host \(output.host)."
  548. case let .hostValidationFailed(output):
  549. return "Host validation failed for host \(output.host)."
  550. case let .revocationCheckFailed(output, _):
  551. return "Revocation check failed for host \(output.host)."
  552. case let .certificatePinningFailed(host, _, _, _):
  553. return "Certificate pinning failed for host \(host)."
  554. case let .publicKeyPinningFailed(host, _, _, _):
  555. return "Public key pinning failed for host \(host)."
  556. }
  557. }
  558. }