Sin descripción

UserFacingErrorMessage.swift 858B

123456789101112131415161718192021222324
  1. import Foundation
  2. /// Maps backend and network errors to short, safe copy for the UI.
  3. enum UserFacingErrorMessage {
  4. static func jobSearchFailure(_ error: Error) -> String {
  5. if let urlError = error as? URLError {
  6. switch urlError.code {
  7. case .notConnectedToInternet,
  8. .networkConnectionLost,
  9. .timedOut,
  10. .cannotFindHost,
  11. .cannotConnectToHost,
  12. .dnsLookupFailed:
  13. return L("We couldn't reach the server. Check your internet connection and try again.")
  14. case .cancelled:
  15. return L("The search was cancelled. Try again when you're ready.")
  16. default:
  17. break
  18. }
  19. }
  20. return L("Something went wrong while searching. Please try again in a moment.")
  21. }
  22. }