PumpManagerError.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // PumpManagerError.swift
  3. // LoopKit
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. public enum PumpManagerError: Error {
  8. /// The manager isn't configured correctly
  9. case configuration(LocalizedError?)
  10. /// The device connection failed
  11. case connection(LocalizedError?)
  12. /// The device is connected, but communication failed
  13. case communication(LocalizedError?)
  14. /// The device is in an error state
  15. case deviceState(LocalizedError?)
  16. /// A command issued to the pump was sent, but we do not know if the pump received it
  17. case uncertainDelivery
  18. }
  19. extension PumpManagerError: LocalizedError {
  20. public var errorDescription: String? {
  21. switch self {
  22. case .communication(let error):
  23. return error?.errorDescription ?? LocalizedString("Communication Failure", comment: "Generic pump error description")
  24. case .configuration(let error):
  25. return error?.errorDescription ?? LocalizedString("Invalid Configuration", comment: "Generic pump error description")
  26. case .connection(let error):
  27. return error?.errorDescription ?? LocalizedString("Connection Failure", comment: "Generic pump error description")
  28. case .deviceState(let error):
  29. return error?.errorDescription ?? LocalizedString("Device Refused", comment: "Generic pump error description")
  30. case .uncertainDelivery:
  31. return LocalizedString("Uncertain Delivery", comment: "Error description for uncertain delivery")
  32. }
  33. }
  34. public var failureReason: String? {
  35. switch self {
  36. case .communication(let error):
  37. return error?.failureReason
  38. case .configuration(let error):
  39. return error?.failureReason
  40. case .connection(let error):
  41. return error?.failureReason
  42. case .deviceState(let error):
  43. return error?.failureReason
  44. case .uncertainDelivery:
  45. return LocalizedString("Communications interrupted during insulin delivery command.", comment: "Failure reason for uncertain delivery")
  46. }
  47. }
  48. public var recoverySuggestion: String? {
  49. switch self {
  50. case .communication(let error):
  51. return error?.recoverySuggestion
  52. case .configuration(let error):
  53. return error?.recoverySuggestion
  54. case .connection(let error):
  55. return error?.recoverySuggestion
  56. case .deviceState(let error):
  57. return error?.recoverySuggestion
  58. case .uncertainDelivery:
  59. return LocalizedString("Make sure your pump is within communication range of your phone.", comment: "Recovery suggestion for uncertain delivery")
  60. }
  61. }
  62. public var helpAnchor: String? {
  63. switch self {
  64. case .communication(let error):
  65. return error?.helpAnchor
  66. case .configuration(let error):
  67. return error?.helpAnchor
  68. case .connection(let error):
  69. return error?.helpAnchor
  70. case .deviceState(let error):
  71. return error?.helpAnchor
  72. case .uncertainDelivery:
  73. return nil
  74. }
  75. }
  76. }