From c63afb5983646a543511e10c7e4a7400f8b742f3 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sun, 2 Sep 2018 14:41:13 -0500 Subject: [PATCH] Handle pageDoesNotExist error from pump during history fetching --- MinimedKit/Messages/PumpErrorMessageBody.swift | 3 +++ RileyLinkKit/PumpOpsSession.swift | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/MinimedKit/Messages/PumpErrorMessageBody.swift b/MinimedKit/Messages/PumpErrorMessageBody.swift index ea91b3ee6..ffff07b05 100644 --- a/MinimedKit/Messages/PumpErrorMessageBody.swift +++ b/MinimedKit/Messages/PumpErrorMessageBody.swift @@ -13,6 +13,7 @@ public enum PumpErrorCode: UInt8, CustomStringConvertible { case commandRefused = 0x08 case maxSettingExceeded = 0x09 case bolusInProgress = 0x0c + case pageDoesNotExist = 0x0d public var description: String { switch self { @@ -22,6 +23,8 @@ public enum PumpErrorCode: UInt8, CustomStringConvertible { return LocalizedString("Max setting exceeded", comment: "Pump error code describing max setting exceeded") case .bolusInProgress: return LocalizedString("Bolus in progress", comment: "Pump error code when bolus is in progress") + case .pageDoesNotExist: + return LocalizedString("History page does not exist", comment: "Pump error code when invalid history page is requested") } } diff --git a/RileyLinkKit/PumpOpsSession.swift b/RileyLinkKit/PumpOpsSession.swift index 6df0e151b..e7c8cd59e 100644 --- a/RileyLinkKit/PumpOpsSession.swift +++ b/RileyLinkKit/PumpOpsSession.swift @@ -963,8 +963,11 @@ extension PumpOpsSession { do { pageData = try getHistoryPage(pageNum) - } catch PumpOpsError.pumpError { - break pages + } catch PumpCommandError.arguments(let error) { + if case PumpOpsError.pumpError(.pageDoesNotExist) = error { + return (events, pumpModel) + } + throw PumpCommandError.arguments(error) } var idx = 0