MinimedPumpManagerError.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // MinimedPumpManagerError.swift
  3. // Loop
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import Foundation
  8. public enum MinimedPumpManagerError: Error {
  9. case noRileyLink
  10. case bolusInProgress
  11. case noDate // TODO: This is less of an error and more of a precondition/assertion state
  12. case tuneFailed(LocalizedError)
  13. case commsError(LocalizedError)
  14. case storageFailure
  15. }
  16. extension MinimedPumpManagerError: LocalizedError {
  17. public var errorDescription: String? {
  18. switch self {
  19. case .noRileyLink:
  20. return LocalizedString("No RileyLink Connected", comment: "Error description when no rileylink connected")
  21. case .bolusInProgress:
  22. return LocalizedString("Bolus in Progress", comment: "Error description when failure due to bolus in progress")
  23. case .noDate:
  24. return nil
  25. case .tuneFailed(let error):
  26. return [LocalizedString("RileyLink radio tune failed", comment: "Error description for tune failure"), error.errorDescription].compactMap({ $0 }).joined(separator: ": ")
  27. case .commsError(let error):
  28. return error.errorDescription
  29. case .storageFailure:
  30. return LocalizedString("Unable to store pump data", comment: "Error description when storage fails")
  31. }
  32. }
  33. public var failureReason: String? {
  34. switch self {
  35. case .tuneFailed(let error):
  36. return error.failureReason
  37. default:
  38. return nil
  39. }
  40. }
  41. public var recoverySuggestion: String? {
  42. switch self {
  43. case .noRileyLink:
  44. return LocalizedString("Make sure your RileyLink is nearby and powered on", comment: "Recovery suggestion")
  45. case .tuneFailed(let error):
  46. return error.recoverySuggestion
  47. default:
  48. return nil
  49. }
  50. }
  51. }