Skip to content

Commit

Permalink
fix(Auth): Add underlying error details to session error
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Nov 15, 2023
1 parent a659848 commit 1e30a80
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct InformSessionError: Action {
switch error {
case .service(let serviceError):
if isNotAuthorizedError(serviceError) {
event = .init(eventType: .throwError(.sessionExpired))
event = .init(eventType: .throwError(
.sessionExpired(error: serviceError)))
} else {
event = .init(eventType: .receivedSessionError(error))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class FetchAuthSessionOperationHelper: DefaultLogger {
forceRefresh: forceRefresh)

case .error(let error):
if case .sessionExpired = error {
if case .sessionExpired(let error) = error {
log.verbose("Session is expired")
let session = AuthCognitoSignedInSessionHelper.makeExpiredSignedInSession()
let session = AuthCognitoSignedInSessionHelper.makeExpiredSignedInSession(
underlyingError: error)
return session
} else if case .sessionError(_, let credentials) = error {
return try await refreshIfRequired(
Expand Down Expand Up @@ -125,8 +126,9 @@ class FetchAuthSessionOperationHelper: DefaultLogger {
return try sessionResultWithFetchError(fetchError,
authenticationState: authenticationState,
existingCredentials: credentials)
case .sessionExpired:
let session = AuthCognitoSignedInSessionHelper.makeExpiredSignedInSession()
case .sessionExpired(let error):
let session = AuthCognitoSignedInSessionHelper.makeExpiredSignedInSession(
underlyingError: error)
return session
default:
let message = "Unknown error occurred"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ enum AuthorizationError: Error {
case service(error: Swift.Error)
case invalidState(message: String)
case sessionError(FetchSessionError, AmplifyCredentials)
case sessionExpired
case sessionExpired(error: Error)
}

extension AuthorizationError: AuthErrorConvertible {
var authError: AuthError {
switch self {
case .sessionExpired:
return .sessionExpired("", "", nil)
case .sessionExpired(let error):
return .sessionExpired("", "", error)
case .configuration(let message):
return .configuration(message, "")
case .service(let error):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ struct AuthCognitoSignedInSessionHelper {
return authSession
}

static func makeExpiredSignedInSession() -> AWSAuthCognitoSession {
static func makeExpiredSignedInSession(underlyingError: Error) -> AWSAuthCognitoSession {
let identityIdError = AuthError.sessionExpired(
AuthPluginErrorConstants.identityIdSessionExpiredError.errorDescription,
AuthPluginErrorConstants.identityIdSessionExpiredError.recoverySuggestion)
AuthPluginErrorConstants.identityIdSessionExpiredError.recoverySuggestion,
underlyingError)

let awsCredentialsError = AuthError.sessionExpired(
AuthPluginErrorConstants.awsCredentialsSessionExpiredError.errorDescription,
AuthPluginErrorConstants.awsCredentialsSessionExpiredError.recoverySuggestion)
AuthPluginErrorConstants.awsCredentialsSessionExpiredError.recoverySuggestion,
underlyingError)

let tokensError = AuthError.sessionExpired(
AuthPluginErrorConstants.cognitoTokensSessionExpiredError.errorDescription,
AuthPluginErrorConstants.cognitoTokensSessionExpiredError.recoverySuggestion)
AuthPluginErrorConstants.cognitoTokensSessionExpiredError.recoverySuggestion,
underlyingError)

let authSession = AWSAuthCognitoSession(isSignedIn: true,
identityIdResult: .failure(identityIdError),
Expand Down

0 comments on commit 1e30a80

Please sign in to comment.