Skip to content

Commit 068bd3c

Browse files
authored
fix(Authenticator): Allowing to only override the desired errors when invoking the errorMap functions (#93)
1 parent eb0fd93 commit 068bd3c

19 files changed

+40
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.1.7 (2024-09-13)
4+
5+
### Bug Fixes
6+
- **Authenticator**: Allowing to only override the desired errors when invoking the errorMap functions (#93)
7+
38
## 1.1.6 (2024-08-13)
49

510
### Bug Fixes

Sources/Authenticator/Authenticator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public struct Authenticator<LoadingContent: View,
290290

291291
/// Sets a custom error mapping function for the `AuthError`s that are displayed
292292
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
293-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
293+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
294294
for contentState in contentStates.allObjects {
295295
contentState.errorTransform = errorTransform
296296
}

Sources/Authenticator/Constants/ComponentInformation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
import Foundation
99

1010
public class ComponentInformation {
11-
public static let version = "1.1.6"
11+
public static let version = "1.1.7"
1212
public static let name = "amplify-ui-swift-authenticator"
1313
}

Sources/Authenticator/States/AuthenticatorBaseState.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class AuthenticatorBaseState: ObservableObject {
2323

2424
@ObservedObject var credentials: Credentials
2525

26-
var errorTransform: ((AuthError) -> AuthenticatorError)? = nil
26+
var errorTransform: ((AuthError) -> AuthenticatorError?)? = nil
2727
private(set) var authenticatorState: AuthenticatorStateProtocol = .empty
2828

2929
init(credentials: Credentials) {
@@ -183,8 +183,8 @@ public class AuthenticatorBaseState: ObservableObject {
183183
return .unknown(from: error)
184184
}
185185

186-
if let errorTransform = errorTransform {
187-
return errorTransform(authError)
186+
if let customError = errorTransform?(authError) {
187+
return customError
188188
}
189189

190190
if let localizedMessage = localizedMessage(for: authError) {

Sources/Authenticator/Views/ConfirmResetPasswordView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public struct ConfirmResetPasswordView<Header: View,
135135

136136
/// Sets a custom error mapping function for the `AuthError`s that are displayed
137137
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
138-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
138+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
139139
state.errorTransform = errorTransform
140140
return self
141141
}

Sources/Authenticator/Views/ConfirmSignInWithCustomChallengeView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct ConfirmSignInWithCustomChallengeView<Header: View,
4242

4343
/// Sets a custom error mapping function for the `AuthError`s that are displayed
4444
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
45-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
45+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
4646
state.errorTransform = errorTransform
4747
return self
4848
}

Sources/Authenticator/Views/ConfirmSignInWithMFACodeView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public struct ConfirmSignInWithMFACodeView<Header: View,
4848

4949
/// Sets a custom error mapping function for the `AuthError`s that are displayed
5050
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
51-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
51+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
5252
state.errorTransform = errorTransform
5353
return self
5454
}

Sources/Authenticator/Views/ConfirmSignInWithNewPasswordView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public struct ConfirmSignInWithNewPasswordView<Header: View,
111111

112112
/// Sets a custom error mapping function for the `AuthError`s that are displayed
113113
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
114-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
114+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
115115
state.errorTransform = errorTransform
116116
return self
117117
}

Sources/Authenticator/Views/ConfirmSignInWithTOTPCodeView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct ConfirmSignInWithTOTPView<Header: View,
4343

4444
/// Sets a custom error mapping function for the `AuthError`s that are displayed
4545
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
46-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
46+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
4747
state.errorTransform = errorTransform
4848
return self
4949
}

Sources/Authenticator/Views/ConfirmSignUpView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public struct ConfirmSignUpView<Header: View,
9898

9999
/// Sets a custom error mapping function for the `AuthError`s that are displayed
100100
/// - Parameter errorTransform: A closure that takes an `AuthError` and returns a ``AuthenticatorError`` that will be displayed.
101-
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError) -> Self {
101+
public func errorMap(_ errorTransform: @escaping (AuthError) -> AuthenticatorError?) -> Self {
102102
state.errorTransform = errorTransform
103103
return self
104104
}

0 commit comments

Comments
 (0)