Skip to content

Commit 9f21487

Browse files
authored
fix: Displaying the correct message on connectivity errors (#82)
* chore: Unpinning Amplify version * fix: Displaying the correct message on connectivity errors * chore: Updating CHANGELOG for release
1 parent 15e2d84 commit 9f21487

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

CHANGELOG.md

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

3+
## 1.1.4 (2024-06-07)
4+
5+
### Bug Fixes
6+
- **Authenticator**: Showing the proper message when there's connectivity issues (#82)
7+
8+
### Misc. Updates
9+
- Updating code to support Amplify 2.35+. (#82)
10+
311
## 1.1.3 (2024-06-04)
412

513
### Bug Fixes

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
targets: ["Authenticator"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/aws-amplify/amplify-swift", "2.16.0"..<"2.35.0"),
16+
.package(url: "https://github.com/aws-amplify/amplify-swift", from: "2.35.0"),
1717
],
1818
targets: [
1919
.target(

Sources/Authenticator/Models/AuthenticatorState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Amplify
99
@_spi(InternalAmplifyPluginExtension) import AWSCognitoAuthPlugin
10-
@_spi(InternalAmplifyPluginExtension) import AWSPluginsCore
10+
@_spi(InternalAmplifyPluginExtension) import InternalAmplifyCredentials
1111
import Foundation
1212

1313
/// An `ObservableObject` that represents the Authenticator's state

Sources/Authenticator/States/AuthenticatorBaseState.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ public class AuthenticatorBaseState: ObservableObject {
213213
}
214214
}
215215

216+
// First check if the underlying error is a connectivity one
217+
if isConnectivityError(error.underlyingError) {
218+
log.verbose("The error is identified as a connectivity issue, displaying the corresponding localized string.")
219+
return "authenticator.cognitoError.network".localized()
220+
}
221+
216222
guard let cognitoError = error.underlyingError as? AWSCognitoAuthError else {
217223
log.verbose("Unable to localize error that is not of type AWSCognitoAuthError")
218224
return nil
@@ -229,6 +235,20 @@ public class AuthenticatorBaseState: ObservableObject {
229235
log.verbose("No localizable string was found for error of type '\(cognitoError)'")
230236
return nil
231237
}
238+
239+
private func isConnectivityError(_ error: Error?) -> Bool {
240+
guard let error = error as? NSError else {
241+
return false
242+
}
243+
let networkErrorCodes = [
244+
NSURLErrorCannotFindHost,
245+
NSURLErrorCannotConnectToHost,
246+
NSURLErrorNetworkConnectionLost,
247+
NSURLErrorDNSLookupFailed,
248+
NSURLErrorNotConnectedToInternet
249+
]
250+
return networkErrorCodes.contains(where: { $0 == error.code })
251+
}
232252
}
233253

234254
extension AuthenticatorBaseState: Equatable {

0 commit comments

Comments
 (0)