Skip to content

Commit

Permalink
🔨 Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Aug 30, 2023
1 parent 8fbe026 commit 44e2538
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Binary file not shown.
7 changes: 6 additions & 1 deletion Sources/EasyFirebase/Services/Firestore/Listening.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ extension EasyFirestore {
if snapshot.data() == nil {
onUpdate(nil)
}
try? document = snapshot.data(as: T.self)
do {
try document = snapshot.data(as: T.self)
} catch {
print(error.localizedDescription)
return
}
guard let document = document else {
EasyFirebase.log(error: "A document loaded from the [\(colName(of: T.self))] collection, but couldn't be decoded.")
return
Expand Down
15 changes: 11 additions & 4 deletions Sources/EasyFirebase/Services/Firestore/Retrieval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ extension EasyFirestore {
db.collection(collection).document(id).getDocument { result, error in
var document: T?
if let result = result, result.exists {
try? document = result.data(as: type)
do {
try document = result.data(as: type)
} catch {
print(error)
}
} else if let error = error {
EasyFirebase.log(error.localizedDescription)
} else {
Expand Down Expand Up @@ -142,11 +146,14 @@ extension EasyFirestore {
}
let documents = snapshot?.documents ?? []
let objects: [T] = documents.compactMap { doc in
let item = try? doc.data(as: T.self)
if let item = item {
do {
let item = try doc.data(as: T.self)
Cacheing.register(item)
return item
} catch {
print(error.localizedDescription)
return nil
}
return item
}
toReturn <= objects
completion(toReturn)
Expand Down

0 comments on commit 44e2538

Please sign in to comment.