Skip to content

Commit 8b2c906

Browse files
chore: make reportError() optionally called
1 parent bc040dd commit 8b2c906

File tree

11 files changed

+87
-31
lines changed

11 files changed

+87
-31
lines changed

FirebaseSwiftUI/FirebaseAppleSwiftUI/Sources/Views/SignInWithAppleButton.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ extension SignInWithAppleButton: View {
3737
Task {
3838
do {
3939
_ = try await authService.signIn(provider)
40-
} catch let caughtError {
41-
reportError(caughtError)
40+
} catch {
41+
if let errorHandler = reportError {
42+
errorHandler(error)
43+
} else {
44+
throw error
45+
}
4246
}
4347
}
4448
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailAuthView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,24 @@ public struct EmailAuthView {
5353
private func signInWithEmailPassword() async {
5454
do {
5555
_ = try await authService.signIn(email: email, password: password)
56-
} catch let caughtError {
57-
reportError(caughtError)
56+
} catch {
57+
if let errorHandler = reportError {
58+
errorHandler(error)
59+
} else {
60+
throw error
61+
}
5862
}
5963
}
6064

6165
private func createUserWithEmailPassword() async {
6266
do {
6367
_ = try await authService.createUser(email: email, password: password)
64-
} catch let caughtError {
65-
reportError(caughtError)
68+
} catch {
69+
if let errorHandler = reportError {
70+
errorHandler(error)
71+
} else {
72+
throw error
73+
}
6674
}
6775
}
6876
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailLinkView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ public struct EmailLinkView {
2929
do {
3030
try await authService.sendEmailSignInLink(email: email)
3131
showModal = true
32-
} catch let caughtError {
33-
reportError(caughtError)
32+
} catch {
33+
if let errorHandler = reportError {
34+
errorHandler(error)
35+
} else {
36+
throw error
37+
}
3438
}
3539
}
3640
}
@@ -89,8 +93,12 @@ extension EmailLinkView: View {
8993
Task {
9094
do {
9195
try await authService.handleSignInLink(url: url)
92-
} catch let caughtError {
93-
reportError(caughtError)
96+
} catch {
97+
if let errorHandler = reportError {
98+
errorHandler(error)
99+
} else {
100+
throw error
101+
}
94102
}
95103
}
96104
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterPhoneNumberView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ struct EnterPhoneNumberView: View {
5555
verificationID: id,
5656
fullPhoneNumber: fullPhoneNumber
5757
))
58-
} catch let caughtError {
59-
reportError(caughtError)
58+
} catch {
59+
if let errorHandler = reportError {
60+
errorHandler(error)
61+
} else {
62+
throw error
63+
}
6064
}
6165
}
6266
}) {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterVerificationCodeView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ struct EnterVerificationCodeView: View {
5858
verificationCode: verificationCode
5959
)
6060
authService.navigator.clear()
61-
} catch let caughtError {
62-
reportError(caughtError)
61+
} catch {
62+
if let errorHandler = reportError {
63+
errorHandler(error)
64+
} else {
65+
throw error
66+
}
6367
}
6468
}
6569
}) {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/ErrorAlertView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ public struct AlertError: Identifiable, Equatable {
8888

8989
/// Environment key for error reporting closure
9090
private struct ReportErrorKey: @preconcurrency EnvironmentKey {
91-
@MainActor static let defaultValue: (Error) -> Void = { _ in }
91+
@MainActor static let defaultValue: ((Error) -> Void)? = nil
9292
}
9393

9494
public extension EnvironmentValues {
95-
/// Closure to report errors to the parent view for display
96-
var reportError: (Error) -> Void {
95+
/// Optional closure to report errors to the parent view for display
96+
var reportError: ((Error) -> Void)? {
9797
get { self[ReportErrorKey.self] }
9898
set { self[ReportErrorKey.self] = newValue }
9999
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public struct SignedInView {
2626
do {
2727
try await authService.sendEmailVerification()
2828
showEmailVerificationSent = true
29-
} catch let caughtError {
30-
reportError(caughtError)
29+
} catch {
30+
if let errorHandler = reportError {
31+
errorHandler(error)
32+
} else {
33+
throw error
34+
}
3135
}
3236
}
3337
}
@@ -99,8 +103,12 @@ extension SignedInView: View {
99103
Task {
100104
do {
101105
try await authService.signOut()
102-
} catch let caughtError {
103-
reportError(caughtError)
106+
} catch {
107+
if let errorHandler = reportError {
108+
errorHandler(error)
109+
} else {
110+
throw error
111+
}
104112
}
105113
}
106114
} label: {
@@ -121,8 +129,12 @@ extension SignedInView: View {
121129
Task {
122130
do {
123131
try await authService.deleteUser()
124-
} catch let caughtError {
125-
reportError(caughtError)
132+
} catch {
133+
if let errorHandler = reportError {
134+
errorHandler(error)
135+
} else {
136+
throw error
137+
}
126138
}
127139
}
128140
},

FirebaseSwiftUI/FirebaseFacebookSwiftUI/Sources/Views/SignInWithFacebookButton.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ extension SignInWithFacebookButton: View {
4040
Task {
4141
do {
4242
_ = try await authService.signIn(facebookProvider)
43-
} catch let caughtError {
44-
reportError(caughtError)
43+
} catch {
44+
if let errorHandler = reportError {
45+
errorHandler(error)
46+
} else {
47+
throw error
48+
}
4549
}
4650
}
4751
}

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Views/SignInWithGoogleButton.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ extension SignInWithGoogleButton: View {
4444
Task {
4545
do {
4646
_ = try await authService.signIn(googleProvider)
47-
} catch let caughtError {
48-
reportError(caughtError)
47+
} catch {
48+
if let errorHandler = reportError {
49+
errorHandler(error)
50+
} else {
51+
throw error
52+
}
4953
}
5054
}
5155
}

FirebaseSwiftUI/FirebaseOAuthSwiftUI/Sources/Views/GenericOAuthButton.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ extension GenericOAuthButton: View {
4747
Task {
4848
do {
4949
_ = try await authService.signIn(provider)
50-
} catch let caughtError {
51-
reportError(caughtError)
50+
} catch {
51+
if let errorHandler = reportError {
52+
errorHandler(error)
53+
} else {
54+
throw error
55+
}
5256
}
5357
}
5458
}

0 commit comments

Comments
 (0)