Skip to content

Commit edf63cc

Browse files
committed
bullet-proofing against nullpointerexceptions for caching
1 parent 0b94ebd commit edf63cc

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Spawn-App-iOS-SwiftUI/Services/API/APIService.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,12 @@ class APIService: IAPIService {
905905
func validateCache(_ cachedItems: [String: Date]) async throws -> [String: CacheValidationResponse] {
906906
resetState()
907907

908+
// Don't send validation request if there are no cached items to validate
909+
if cachedItems.isEmpty {
910+
print("No cached items to validate, returning empty response")
911+
return [:]
912+
}
913+
908914
guard let userId = UserAuthViewModel.shared.spawnUser?.id else {
909915
throw APIError.invalidData
910916
}

Spawn-App-iOS-SwiftUI/Services/API/MockAPIService.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ class MockAPIService: IAPIService {
404404
func validateCache(_ cachedItems: [String: Date]) async throws -> [String:
405405
CacheValidationResponse]
406406
{
407+
// Don't send validation request if there are no cached items to validate
408+
if cachedItems.isEmpty {
409+
print("MOCK: No cached items to validate, returning empty response")
410+
return [:]
411+
}
412+
407413
// In the mock implementation, we'll pretend everything is fresh except for items
408414
// that are older than 30 minutes
409415
var result: [String: CacheValidationResponse] = [:]

Spawn-App-iOS-SwiftUI/Services/AppCache.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class AppCache: ObservableObject {
7070
return
7171
}
7272

73+
// Don't send validation request if we have no cached items to validate
74+
if lastChecked.isEmpty {
75+
print("No cached items to validate, skipping cache validation")
76+
return
77+
}
78+
7379
do {
7480
let apiService: IAPIService = MockAPIService.isMocking ? MockAPIService(userId: userId) : APIService()
7581
let result = try await apiService.validateCache(lastChecked)

0 commit comments

Comments
 (0)