Skip to content

Commit 446116b

Browse files
Catch deleteAllTasks exception
1 parent bae10f1 commit 446116b

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

swift-sdk/Internal/HealthMonitor.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class HealthMonitor {
8686
onError()
8787
}
8888

89+
func onDeleteAllTasksError() {
90+
ITBInfo()
91+
onError()
92+
}
93+
8994
private func onError() {
9095
errored = true
9196
delegate?.onDBError()

swift-sdk/Internal/IterableTaskScheduler.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ class IterableTaskScheduler {
4040
return Result.success(taskId)
4141
}
4242

43-
func deleteAllTasks() throws {
43+
func deleteAllTasks() {
4444
ITBInfo()
45-
try persistenceContextProvider.mainQueueContext().deleteAllTasks()
45+
do {
46+
try persistenceContextProvider.mainQueueContext().deleteAllTasks()
47+
} catch let error {
48+
ITBError("deleteAllTasks: \(error.localizedDescription)")
49+
healthMonitor.onDeleteAllTasksError()
50+
}
4651
}
4752

4853
private let persistenceContextProvider: IterablePersistenceContextProvider

swift-sdk/Internal/OfflineRequestProcessor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ struct OfflineRequestProcessor: RequestProcessorProtocol {
244244
identifier: #function)
245245
}
246246

247-
func deleteAllTasks() throws {
247+
func deleteAllTasks() {
248248
ITBInfo()
249-
try taskScheduler.deleteAllTasks()
249+
taskScheduler.deleteAllTasks()
250250
}
251251

252252
private let apiKey: String

swift-sdk/Internal/RequestHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class RequestHandler: RequestHandlerProtocol {
250250

251251
func handleLogout() throws {
252252
if offlineMode {
253-
try offlineProcessor?.deleteAllTasks()
253+
offlineProcessor?.deleteAllTasks()
254254
}
255255
}
256256

tests/offline-events-tests/HealthMonitorTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ class HealthMonitorTests: XCTestCase {
165165
XCTAssertFalse(internalAPI.requestHandler.offlineMode)
166166
}
167167

168+
func testDeleteAllTasksException() throws {
169+
let networkSession = MockNetworkSession(statusCode: 200)
170+
let localStorage = MockLocalStorage()
171+
localStorage.email = "[email protected]"
172+
localStorage.offlineModeBeta = true
173+
var input = MockPersistenceContext.Input()
174+
input.deleteAllTasksCallback = {
175+
throw IterableDBError.general("error deleting all tasks")
176+
}
177+
let context = MockPersistenceContext(input: input)
178+
let internalAPI = InternalIterableAPI.initializeForTesting(networkSession: networkSession,
179+
localStorage: localStorage,
180+
persistenceContextProvider: MockPersistenceContextProvider(context: context))
181+
XCTAssertTrue(internalAPI.requestHandler.offlineMode)
182+
internalAPI.email = "[email protected]"
183+
XCTAssertFalse(internalAPI.requestHandler.offlineMode)
184+
}
185+
168186
private let dateProvider = MockDateProvider()
169187

170188
private lazy var persistenceProvider: IterablePersistenceContextProvider = {

0 commit comments

Comments
 (0)