Skip to content

Commit 1e3befb

Browse files
committed
feat: catch the throwing error and resume it to the continuation
1 parent 5d81cfa commit 1e3befb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Firestore/Swift/Source/Codable/CollectionReference+WriteEncodable.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ public extension CollectionReference {
6262
-> DocumentReference {
6363
return try await withCheckedThrowingContinuation { continuation in
6464
var document: DocumentReference?
65-
document = self.addDocument(from: value, encoder: encoder) { error in
66-
if let error {
67-
continuation.resume(throwing: error)
68-
} else {
69-
// Our callbacks guarantee that we either return an error or a document.
70-
continuation.resume(returning: document!)
65+
do {
66+
document = try self.addDocument(from: value, encoder: encoder) { error in
67+
if let error {
68+
continuation.resume(throwing: error)
69+
} else {
70+
// Our callbacks guarantee that we either return an error or a document.
71+
continuation.resume(returning: document!)
72+
}
7173
}
74+
} catch {
75+
continuation.resume(throwing: error)
7276
}
7377
}
7478
}

0 commit comments

Comments
 (0)