From af4e2b8af57812b1a2bb477b26d7c6f9788d6608 Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Sat, 27 Jul 2024 15:52:26 +0330 Subject: [PATCH] feat: catch the throwing error and resume it to the continuation --- .../CollectionReference+WriteEncodable.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Firestore/Swift/Source/Codable/CollectionReference+WriteEncodable.swift b/Firestore/Swift/Source/Codable/CollectionReference+WriteEncodable.swift index d1e9d80aaae..e4d52eab7f7 100644 --- a/Firestore/Swift/Source/Codable/CollectionReference+WriteEncodable.swift +++ b/Firestore/Swift/Source/Codable/CollectionReference+WriteEncodable.swift @@ -62,13 +62,17 @@ public extension CollectionReference { -> DocumentReference { return try await withCheckedThrowingContinuation { continuation in var document: DocumentReference? - document = self.addDocument(from: value, encoder: encoder) { error in - if let error { - continuation.resume(throwing: error) - } else { - // Our callbacks guarantee that we either return an error or a document. - continuation.resume(returning: document!) + do { + document = try self.addDocument(from: value, encoder: encoder) { error in + if let error { + continuation.resume(throwing: error) + } else { + // Our callbacks guarantee that we either return an error or a document. + continuation.resume(returning: document!) + } } + } catch { + continuation.resume(throwing: error) } } }