diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift index ae80ff67f2..ab44a86fc8 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift @@ -86,10 +86,10 @@ extension AWSCognitoAuthPlugin { private func makeUserPool() throws -> CognitoUserPoolBehavior { switch authConfiguration { case .userPools(let userPoolConfig), .userPoolsAndIdentityPools(let userPoolConfig, _): + // TODO: FrameworkMetadata Replacement let configuration = try CognitoIdentityProviderClient.CognitoIdentityProviderClientConfiguration( - endpointResolver: userPoolConfig.endpoint?.resolver, - frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(), - region: userPoolConfig.region + region: userPoolConfig.region, + serviceSpecific: .init(endpointResolver: userPoolConfig.endpoint?.resolver) ) if var httpClientEngineProxy = httpClientEngineProxy { @@ -121,8 +121,8 @@ extension AWSCognitoAuthPlugin { private func makeIdentityClient() throws -> CognitoIdentityBehavior { switch authConfiguration { case .identityPools(let identityPoolConfig), .userPoolsAndIdentityPools(_, let identityPoolConfig): + // TODO: FrameworkMetadata Replacement let configuration = try CognitoIdentityClient.CognitoIdentityClientConfiguration( - frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(), region: identityPoolConfig.region ) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/FetchIdentity/FetchAuthIdentityId.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/FetchIdentity/FetchAuthIdentityId.swift index da2a09c174..97ffabda08 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/FetchIdentity/FetchAuthIdentityId.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/FetchIdentity/FetchAuthIdentityId.swift @@ -65,12 +65,7 @@ struct FetchAuthIdentityId: Action { } func isNotAuthorizedError(_ error: Error) -> Bool { - - if let getIdError: GetIdOutputError = error.internalAWSServiceError(), - case .notAuthorizedException = getIdError { - return true - } - return false + error is AWSCognitoIdentity.NotAuthorizedException } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift index 6c6107578f..c556bf89d4 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift @@ -37,17 +37,8 @@ struct InformSessionError: Action { } func isNotAuthorizedError(_ error: Error) -> Bool { - - - if let serviceError: GetCredentialsForIdentityOutputError = error.internalAWSServiceError(), - case .notAuthorizedException = serviceError { - return true - } - if let serviceError: InitiateAuthOutputError = error.internalAWSServiceError(), - case .notAuthorizedException = serviceError { - return true - } - return false + error is AWSCognitoIdentity.NotAuthorizedException + || error is AWSCognitoIdentityProvider.NotAuthorizedException } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift index ec5ccf0ade..969b2b1c93 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift @@ -110,11 +110,7 @@ struct VerifyPasswordSRP: Action { return false } - if let serviceError: RespondToAuthChallengeOutputError = error.internalAWSServiceError(), - case .resourceNotFoundException = serviceError { - return true - } - return false + return error is AWSCognitoIdentityProvider.ResourceNotFoundException } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/VerifySignInChallenge.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/VerifySignInChallenge.swift index ac19a29d86..5761ac2d06 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/VerifySignInChallenge.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/VerifySignInChallenge.swift @@ -89,11 +89,7 @@ struct VerifySignInChallenge: Action { return false } - if let serviceError: RespondToAuthChallengeOutputError = error.internalAWSServiceError(), - case .resourceNotFoundException = serviceError { - return true - } - return false + return error is AWSCognitoIdentityProvider.ResourceNotFoundException } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift new file mode 100644 index 0000000000..dd16b203a0 --- /dev/null +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift @@ -0,0 +1,116 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import Amplify +import AWSCognitoIdentity +import AWSClientRuntime + +// AWSCognitoIdentity +extension AWSCognitoIdentity.ExternalServiceException: AuthErrorConvertible { + var fallbackDescription: String { "External service threw error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.externalServiceException, + AWSCognitoAuthError.externalServiceException + ) + } +} + +extension AWSCognitoIdentity.InternalErrorException: AuthErrorConvertible { + var fallbackDescription: String { "Internal exception occurred" } + + var authError: AuthError { + .unknown(properties.message ?? fallbackDescription) + } +} + +// AWSCognitoIdentity +extension AWSCognitoIdentity.InvalidIdentityPoolConfigurationException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid IdentityPool Configuration error." } + + var authError: AuthError { + .configuration( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.configurationError + ) + } +} + +extension AWSCognitoIdentity.InvalidParameterException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid parameter error" } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.invalidParameterError, + AWSCognitoAuthError.invalidParameter + ) + } +} + +extension AWSCognitoIdentity.NotAuthorizedException: AuthErrorConvertible { + var fallbackDescription: String { "Not authorized error." } + + var authError: AuthError { + .notAuthorized( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.notAuthorizedError + ) + } +} + +extension AWSCognitoIdentity.ResourceConflictException: AuthErrorConvertible { + var fallbackDescription: String { "Resource conflict error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.resourceConflictException, + AWSCognitoAuthError.resourceConflictException + ) + } +} + +extension AWSCognitoIdentity.ResourceNotFoundException: AuthErrorConvertible { + var fallbackDescription: String { "Resource not found error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.resourceNotFoundError, + AWSCognitoAuthError.resourceNotFound + ) + } +} + +extension AWSCognitoIdentity.TooManyRequestsException: AuthErrorConvertible { + var fallbackDescription: String { "Too many requests error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.tooManyRequestError, + AWSCognitoAuthError.requestLimitExceeded + ) + } +} + + +extension AWSCognitoIdentity.LimitExceededException: AuthErrorConvertible { + var fallbackDescription: String { "Too many requests error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.limitExceededException, + AWSCognitoAuthError.limitExceededException + ) + } +} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift new file mode 100644 index 0000000000..6179940724 --- /dev/null +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift @@ -0,0 +1,361 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import Amplify +import AWSCognitoIdentityProvider +import AWSClientRuntime + +extension ForbiddenException: AuthErrorConvertible { + var fallbackDescription: String { "Access to the requested resource is forbidden" } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.forbiddenError + ) + } +} + +extension InternalErrorException: AuthErrorConvertible { + var fallbackDescription: String { "Internal exception occurred" } + + var authError: AuthError { + .unknown(properties.message ?? fallbackDescription) + } +} + +extension InvalidParameterException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid parameter error" } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.invalidParameterError, + AWSCognitoAuthError.invalidParameter + ) + } +} + +extension InvalidPasswordException: AuthErrorConvertible { + var fallbackDescription: String { "Encountered invalid password." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.invalidPasswordError, + AWSCognitoAuthError.invalidPassword + ) + } +} + +extension LimitExceededException: AuthErrorConvertible { + var fallbackDescription: String { "Limit exceeded error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.limitExceededError, + AWSCognitoAuthError.limitExceeded + ) + } +} + +extension NotAuthorizedException: AuthErrorConvertible { + var fallbackDescription: String { "Not authorized error." } + + var authError: AuthError { + .notAuthorized( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.notAuthorizedError + ) + } +} + +extension PasswordResetRequiredException: AuthErrorConvertible { + var fallbackDescription: String { "Password reset required error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.passwordResetRequired, + AWSCognitoAuthError.passwordResetRequired + ) + } +} + +extension ResourceNotFoundException: AuthErrorConvertible { + var fallbackDescription: String { "Resource not found error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.resourceNotFoundError, + AWSCognitoAuthError.resourceNotFound + ) + } +} + +extension TooManyRequestsException: AuthErrorConvertible { + var fallbackDescription: String { "Too many requests error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.tooManyRequestError, + AWSCognitoAuthError.requestLimitExceeded + ) + } +} + +extension UserNotConfirmedException: AuthErrorConvertible { + var fallbackDescription: String { "User not confirmed error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.userNotConfirmedError, + AWSCognitoAuthError.userNotConfirmed + ) + } +} + +extension UserNotFoundException: AuthErrorConvertible { + var fallbackDescription: String { "User not found error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.userNotFoundError, + AWSCognitoAuthError.userNotFound + ) + } +} + +extension CodeMismatchException: AuthErrorConvertible { + var fallbackDescription: String { "Provided code does not match what the server was expecting." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.codeMismatchError, + AWSCognitoAuthError.codeMismatch + ) + } +} + +extension InvalidLambdaResponseException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid lambda response error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.lambdaError, + AWSCognitoAuthError.lambda + ) + } +} + + +extension ExpiredCodeException: AuthErrorConvertible { + var fallbackDescription: String { "Provided code has expired." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.codeExpiredError, + AWSCognitoAuthError.codeExpired + ) + } +} + +extension TooManyFailedAttemptsException: AuthErrorConvertible { + var fallbackDescription: String { "Too many failed attempts error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.tooManyFailedError, + AWSCognitoAuthError.failedAttemptsLimitExceeded + ) + } +} + +extension UnexpectedLambdaException: AuthErrorConvertible { + var fallbackDescription: String { "Unexpected lambda error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.lambdaError, + AWSCognitoAuthError.lambda + ) + } +} + +extension UserLambdaValidationException: AuthErrorConvertible { + var fallbackDescription: String { "User lambda validation error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.lambdaError, + AWSCognitoAuthError.lambda + ) + } +} + +extension AliasExistsException: AuthErrorConvertible { + var fallbackDescription: String { "Alias exists error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.aliasExistsError, + AWSCognitoAuthError.aliasExists + ) + } +} + +extension InvalidUserPoolConfigurationException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid UserPool Configuration error." } + + var authError: AuthError { + .configuration( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.configurationError + ) + } +} + +extension CodeDeliveryFailureException: AuthErrorConvertible { + var fallbackDescription: String { "Code Delivery Failure error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.codeDeliveryError, + AWSCognitoAuthError.codeDelivery + ) + } +} + +extension InvalidEmailRoleAccessPolicyException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid email role access policy error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.invalidEmailRoleError, + AWSCognitoAuthError.emailRole + ) + } +} + + +extension InvalidSmsRoleAccessPolicyException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid SMS Role Access Policy error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.invalidSMSRoleError, + AWSCognitoAuthError.smsRole + ) + } +} + +extension InvalidSmsRoleTrustRelationshipException: AuthErrorConvertible { + var fallbackDescription: String { "Invalid SMS Role Trust Relationship error." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.invalidSMSRoleError, + AWSCognitoAuthError.smsRole + ) + } +} + +extension MFAMethodNotFoundException: AuthErrorConvertible { + var fallbackDescription: String { "Amazon Cognito cannot find a multi-factor authentication (MFA) method." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.mfaMethodNotFoundError, + AWSCognitoAuthError.mfaMethodNotFound + ) + } +} + +extension SoftwareTokenMFANotFoundException: AuthErrorConvertible { + var fallbackDescription: String { "Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool." } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.softwareTokenNotFoundError, + AWSCognitoAuthError.softwareTokenMFANotEnabled + ) + } +} + +extension UsernameExistsException: AuthErrorConvertible { + var fallbackDescription: String { "Username exists error" } + + var authError: AuthError { + .service( + properties.message ?? fallbackDescription, + AuthPluginErrorConstants.userNameExistsError, + AWSCognitoAuthError.usernameExists + ) + } +} + +extension AWSCognitoIdentityProvider.ConcurrentModificationException: AuthErrorConvertible { + var fallbackDescription: String { "Concurrent modification error" } + + var authError: AuthError { + .service( + message ?? fallbackDescription, + AuthPluginErrorConstants.concurrentModificationException + ) + } +} + + +extension AWSCognitoIdentityProvider.EnableSoftwareTokenMFAException: AuthErrorConvertible { + var fallbackDescription: String { "Unable to enable software token MFA" } + + var authError: AuthError { + .service( + message ?? fallbackDescription, + AuthPluginErrorConstants.softwareTokenNotFoundError, + AWSCognitoAuthError.softwareTokenMFANotEnabled + ) + } +} + +extension AWSClientRuntime.UnknownAWSHTTPServiceError: AuthErrorConvertible { + var fallbackDescription: String { "" } + + var authError: AuthError { + .unknown( + """ + Unknown service error occured with: + - status: \(httpResponse.statusCode) + - message: \(message ?? fallbackDescription) + """, + self + ) + } +} + + + + diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AssociateSoftwareTokenOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AssociateSoftwareTokenOutputError+AuthError.swift deleted file mode 100644 index 4adf7e6a0c..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AssociateSoftwareTokenOutputError+AuthError.swift +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Amplify -import AWSCognitoIdentityProvider - -extension AssociateSoftwareTokenOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .concurrentModificationException(let concurrentModificationException): - return .service( - concurrentModificationException.message ?? "Concurrent modification error", - AuthPluginErrorConstants.concurrentModificationException) - case .forbiddenException(let forbiddenException): - return .service( - forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - case .internalErrorException(let internalErrorException): - return .unknown( - internalErrorException.message ?? "Internal exception occurred") - case .invalidParameterException(let invalidParameterException): - return .service( - invalidParameterException.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .notAuthorizedException(let notAuthorizedException): - return .notAuthorized( - notAuthorizedException.message ?? "Not authorized Error", - AuthPluginErrorConstants.notAuthorizedError, - nil) - case .resourceNotFoundException(let resourceNotFoundException): - return AuthError.service( - resourceNotFoundException.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .softwareTokenMFANotFoundException(let exception): - return AuthError.service( - exception.message ?? "Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool.", - AuthPluginErrorConstants.softwareTokenNotFoundError, - AWSCognitoAuthError.mfaMethodNotFound) - case .unknown(let unknownAWSHttpServiceError): - let statusCode = unknownAWSHttpServiceError._statusCode?.rawValue ?? -1 - let message = unknownAWSHttpServiceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AuthErrorConvertible.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AuthErrorConvertible.swift index 34b5a80ba1..e811b761d9 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AuthErrorConvertible.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AuthErrorConvertible.swift @@ -11,7 +11,6 @@ import Amplify /// A type that can be represented as an AuthError /// protocol AuthErrorConvertible { - var authError: AuthError { get } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ChangePasswordOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ChangePasswordOutputError+AuthError.swift deleted file mode 100644 index 0aec3eeb86..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ChangePasswordOutputError+AuthError.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension ChangePasswordOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return AuthError.service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let exception): - return AuthError.service(exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - case .invalidPasswordException(let exception): - return AuthError.service(exception.message ?? "Encountered invalid password.", - AuthPluginErrorConstants.invalidPasswordError, - AWSCognitoAuthError.invalidPassword) - case .limitExceededException(let limitExceededException): - return .service(limitExceededException.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded) - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ClientError+AuthErrorConvertible.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ClientError+AuthErrorConvertible.swift new file mode 100644 index 0000000000..942c410f70 --- /dev/null +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ClientError+AuthErrorConvertible.swift @@ -0,0 +1,33 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import Amplify +import ClientRuntime + +extension ClientError: AuthErrorConvertible { + var fallbackDescription: String { "Client Error" } + + var authError: AuthError { + switch self { + case .pathCreationFailed(let message), + .queryItemCreationFailed(let message), + .serializationFailed(let message), + .dataNotFound(let message): + return .service(message, "", self) + + case .authError(let message): + return .notAuthorized( + message, + "Check if you are authorized to perform the request" + ) + + case .unknownError(let message): + return AuthError.unknown(message, self) + } + } +} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ConfirmForgotPasswordOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ConfirmForgotPasswordOutputError+AuthError.swift deleted file mode 100644 index 9f004cb7a7..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ConfirmForgotPasswordOutputError+AuthError.swift +++ /dev/null @@ -1,81 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension ConfirmForgotPasswordOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .codeMismatchException(let exception): - return AuthError.service(exception.message ?? "Provided code does not match what the server was expecting.", - AuthPluginErrorConstants.codeMismatchError, - AWSCognitoAuthError.codeMismatch) - case .expiredCodeException(let exception): - return AuthError.service(exception.message ?? "Provided code has expired.", - AuthPluginErrorConstants.codeExpiredError, - AWSCognitoAuthError.codeExpired) - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidLambdaResponseException(let exception): - return .service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidPasswordException(let exception): - return AuthError.service(exception.message ?? "Invalid password error", - AuthPluginErrorConstants.invalidPasswordError, - AWSCognitoAuthError.invalidPassword) - case .limitExceededException(let exception): - return .service(exception.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyFailedAttemptsException(let exception): - return AuthError.service(exception.message ?? "Too many failed attempts error", - AuthPluginErrorConstants.tooManyFailedError, - AWSCognitoAuthError.failedAttemptsLimitExceeded) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return .service(exception.message ?? "Unexpected lambda error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userLambdaValidationException(let exception): - return .service(exception.message ?? "User lambda validation error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userNotConfirmedException(let userNotConfirmedException): - return .service(userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ConfirmSignUpOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ConfirmSignUpOutputError+AuthError.swift deleted file mode 100644 index 1a29be5c77..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ConfirmSignUpOutputError+AuthError.swift +++ /dev/null @@ -1,121 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Amplify -import Foundation -import AWSCognitoIdentityProvider - -extension ConfirmSignUpOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .aliasExistsException(let exception): - - return .service( - exception.message ?? "Alias exists error", - AuthPluginErrorConstants.aliasExistsError, - AWSCognitoAuthError.aliasExists - ) - case .codeMismatchException(let exception): - - return .service( - exception.message ?? "Code mismatch error", - AuthPluginErrorConstants.codeMismatchError, - AWSCognitoAuthError.codeMismatch - ) - case .expiredCodeException(let exception): - - return .service( - exception.message ?? "Expired code error", - AuthPluginErrorConstants.codeExpiredError, - AWSCognitoAuthError.codeExpired - ) - case .limitExceededException(let exception): - - return .service( - exception.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded - ) - case .tooManyFailedAttemptsException(let exception): - - return .service( - exception.message ?? "Too many failed attempts error", - AuthPluginErrorConstants.tooManyFailedError, - AWSCognitoAuthError.requestLimitExceeded - ) - case .userNotFoundException(let exception): - - return .service( - exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound - ) - case .internalErrorException(let exception): - - return .unknown( - exception.message ?? "Internal exception occurred" - ) - case .invalidLambdaResponseException(let exception): - - return .service( - exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .invalidParameterException(let exception): - - return .service( - exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter - ) - case .notAuthorizedException(let exception): - - return .notAuthorized( - exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .resourceNotFoundException(let exception): - - return .service( - exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound - ) - case .tooManyRequestsException(let exception): - - return .service( - exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded - ) - case .unexpectedLambdaException(let exception): - - return .service( - exception.message ?? "Unexpected lambda error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .userLambdaValidationException(let exception): - - return .service( - exception.message ?? "User lambda validation error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } - -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/DeleteUserOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/DeleteUserOutputError+AuthError.swift deleted file mode 100644 index a858393471..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/DeleteUserOutputError+AuthError.swift +++ /dev/null @@ -1,55 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension DeleteUserOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authrozied error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return AuthError.service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let exception): - return AuthError.service(exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ForgetDeviceOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ForgetDeviceOutputError+AuthError.swift deleted file mode 100644 index 8208febe99..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ForgetDeviceOutputError+AuthError.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension ForgetDeviceOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidUserPoolConfigurationException(let exception): - return .configuration(exception.message ?? "Invalid UserPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .notAuthorizedException(let exception): - return .notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return .service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return .service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return .service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let userNotConfirmedException): - return .service(userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return .service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ForgotPasswordOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ForgotPasswordOutputError+AuthError.swift deleted file mode 100644 index 7e844880d4..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ForgotPasswordOutputError+AuthError.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension ForgotPasswordOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .codeDeliveryFailureException(let exception): - return .service( - exception.message ?? "Code Delivery Failure error", - AuthPluginErrorConstants.codeDeliveryError, - AWSCognitoAuthError.codeDelivery - ) - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidEmailRoleAccessPolicyException(let exception): - return .service( - exception.message ?? "Invalid email role access policy error", - AuthPluginErrorConstants.invalidEmailRoleError, - AWSCognitoAuthError.emailRole - ) - case .invalidLambdaResponseException(let exception): - return .service( - exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidSmsRoleAccessPolicyException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Access Policy error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole) - case .invalidSmsRoleTrustRelationshipException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Trust Relationship error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole) - case .limitExceededException(let exception): - return .service( - exception.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded - ) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return .service( - exception.message ?? "Unexpected lambda error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .userLambdaValidationException(let exception): - return .service( - exception.message ?? "User lambda validation error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetCredentialsForIdentityOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetCredentialsForIdentityOutputError+AuthError.swift deleted file mode 100644 index 1a26155124..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetCredentialsForIdentityOutputError+AuthError.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentity -import Amplify - -extension GetCredentialsForIdentityOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .externalServiceException(let externalServiceException): - return .service(externalServiceException.message ?? "External service threw error", - AuthPluginErrorConstants.externalServiceException, - AWSCognitoAuthError.externalServiceException) - case .internalErrorException(let internalErrorException): - return .unknown(internalErrorException.message ?? "Internal exception occurred") - case .invalidIdentityPoolConfigurationException(let invalidIdentityPoolConfigurationException): - return AuthError.configuration(invalidIdentityPoolConfigurationException.message ?? "Invalid IdentityPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .invalidParameterException(let invalidParameterException): - return AuthError.service(invalidParameterException.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .notAuthorizedException(let notAuthorizedException): - return .notAuthorized(notAuthorizedException.message ?? "Not authorized Error", - AuthPluginErrorConstants.notAuthorizedError, - nil) - case .resourceConflictException(let resourceConflictException): - return .service(resourceConflictException.message ?? "Resource conflict error", - AuthPluginErrorConstants.resourceConflictException, - AWSCognitoAuthError.resourceConflictException) - case .resourceNotFoundException(let resourceNotFoundException): - return AuthError.service(resourceNotFoundException.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let tooManyRequestsException): - return .service(tooManyRequestsException.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unknown(let unknownAWSHttpServiceError): - let statusCode = unknownAWSHttpServiceError._statusCode?.rawValue ?? -1 - let message = unknownAWSHttpServiceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetIdOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetIdOutputError+AuthError.swift deleted file mode 100644 index 37be0a6d7f..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetIdOutputError+AuthError.swift +++ /dev/null @@ -1,52 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentity -import Amplify - -extension GetIdOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .externalServiceException(let externalServiceException): - return .service(externalServiceException.message ?? "External service threw error", - AuthPluginErrorConstants.externalServiceException, - AWSCognitoAuthError.externalServiceException) - case .internalErrorException(let internalErrorException): - return .unknown(internalErrorException.message ?? "Internal exception occurred") - case .invalidParameterException(let invalidParameterException): - return .service(invalidParameterException.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .limitExceededException(let limitExceededException): - return .service(limitExceededException.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededException, - AWSCognitoAuthError.limitExceededException) - case .notAuthorizedException(let notAuthorizedException): - return .notAuthorized(notAuthorizedException.message ?? "Not authorized Error", - AuthPluginErrorConstants.notAuthorizedError, - nil) - case .resourceConflictException(let resourceConflictException): - return .service(resourceConflictException.message ?? "Resource conflict error", - AuthPluginErrorConstants.resourceConflictException, - AWSCognitoAuthError.resourceConflictException) - case .resourceNotFoundException(let resourceNotFoundException): - return AuthError.service(resourceNotFoundException.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let tooManyRequestsException): - return .service(tooManyRequestsException.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unknown(let unknownAWSHttpServiceError): - let statusCode = unknownAWSHttpServiceError._statusCode?.rawValue ?? -1 - let message = unknownAWSHttpServiceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - } - } - -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetUserAttributeVerificationCodeOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetUserAttributeVerificationCodeOutputError+AuthError.swift deleted file mode 100644 index 073837cb7d..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetUserAttributeVerificationCodeOutputError+AuthError.swift +++ /dev/null @@ -1,88 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension GetUserAttributeVerificationCodeOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .codeDeliveryFailureException(let exception): - return .service(exception.message ?? "Code Delivery Failure error", - AuthPluginErrorConstants.codeDeliveryError, - AWSCognitoAuthError.codeDelivery) - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidEmailRoleAccessPolicyException(let exception): - return .service(exception.message ?? "Invalid email role access policy error", - AuthPluginErrorConstants.invalidEmailRoleError, - AWSCognitoAuthError.emailRole) - case .invalidLambdaResponseException(let exception): - return .service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .invalidParameterException(let exception): - return .service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidSmsRoleAccessPolicyException(let exception): - return .service(exception.message ?? "Invalid SMS Role Access Policy error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.smsRole) - case .invalidSmsRoleTrustRelationshipException(let exception): - return .service(exception.message ?? "Invalid SMS Role Trust Relationship error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.smsRole) - case .limitExceededException(let limitExceededException): - return .service(limitExceededException.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded) - case .notAuthorizedException(let exception): - return .notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return .service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return .service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return .service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return .service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userLambdaValidationException(let exception): - return .service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userNotConfirmedException(let userNotConfirmedException): - return .service(userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let userNotFoundException): - return .service(userNotFoundException.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let unknownAWSHttpServiceError): - let statusCode = unknownAWSHttpServiceError._statusCode?.rawValue ?? -1 - let message = unknownAWSHttpServiceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } - -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetUserOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetUserOutputError+AuthError.swift deleted file mode 100644 index bc364ab427..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/GetUserOutputError+AuthError.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension GetUserOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidParameterException(let exception): - return .service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .notAuthorizedException(let exception): - return .notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return .service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return .service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return .service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let userNotConfirmedException): - return .service(userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let userNotFoundException): - return .service(userNotFoundException.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let unknownAWSHttpServiceError): - let statusCode = unknownAWSHttpServiceError._statusCode?.rawValue ?? -1 - let message = unknownAWSHttpServiceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } - -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/InitiateAuthOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/InitiateAuthOutputError+AuthError.swift deleted file mode 100644 index e4e648af2a..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/InitiateAuthOutputError+AuthError.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension InitiateAuthOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidLambdaResponseException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidSmsRoleAccessPolicyException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Access Policy error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.smsRole) - case .invalidSmsRoleTrustRelationshipException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Trust Relationship error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.smsRole) - case .invalidUserPoolConfigurationException(let exception): - return AuthError.configuration(exception.message ?? "Invalid UserPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return AuthError.service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userLambdaValidationException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userNotConfirmedException(let exception): - return AuthError.service(exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ListDevicesOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ListDevicesOutputError+AuthError.swift deleted file mode 100644 index 42af26acf9..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ListDevicesOutputError+AuthError.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension ListDevicesOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidUserPoolConfigurationException(let exception): - return .configuration(exception.message ?? "Invalid UserPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .notAuthorizedException(let exception): - return .notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return .service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return .service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return .service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let userNotConfirmedException): - return .service(userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return .service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ResendConfirmationCodeOutputError+Error.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ResendConfirmationCodeOutputError+Error.swift deleted file mode 100644 index 2abc4185bb..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/ResendConfirmationCodeOutputError+Error.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension ResendConfirmationCodeOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .codeDeliveryFailureException(let exception): - return .service( - exception.message ?? "Code Delivery Failure error", - AuthPluginErrorConstants.codeDeliveryError, - AWSCognitoAuthError.codeDelivery - ) - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidEmailRoleAccessPolicyException(let exception): - return .service( - exception.message ?? "Invalid email role access policy error", - AuthPluginErrorConstants.invalidEmailRoleError, - AWSCognitoAuthError.emailRole - ) - case .invalidLambdaResponseException(let exception): - return .service( - exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidSmsRoleAccessPolicyException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Access Policy error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole) - case .invalidSmsRoleTrustRelationshipException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Trust Relationship error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole) - case .limitExceededException(let exception): - return .service( - exception.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded - ) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return .service( - exception.message ?? "Unexpected lambda error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .userLambdaValidationException(let exception): - return .service( - exception.message ?? "User lambda validation error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/RespondToAuthChallengeOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/RespondToAuthChallengeOutputError+AuthError.swift deleted file mode 100644 index eae169e4e6..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/RespondToAuthChallengeOutputError+AuthError.swift +++ /dev/null @@ -1,102 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension RespondToAuthChallengeOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .aliasExistsException(let exception): - return AuthError.service(exception.message ?? "An account with this email or phone already exists.", - AuthPluginErrorConstants.aliasExistsError, - AWSCognitoAuthError.aliasExists) - case .codeMismatchException(let exception): - return AuthError.service(exception.message ?? "Provided code does not match what the server was expecting.", - AuthPluginErrorConstants.codeMismatchError, - AWSCognitoAuthError.codeMismatch) - case .expiredCodeException(let exception): - return AuthError.service(exception.message ?? "Provided code has expired.", - AuthPluginErrorConstants.codeExpiredError, - AWSCognitoAuthError.codeExpired) - case .invalidPasswordException(let exception): - return AuthError.service(exception.message ?? "Encountered invalid password.", - AuthPluginErrorConstants.invalidPasswordError, - AWSCognitoAuthError.invalidPassword) - case .mFAMethodNotFoundException(let exception): - return AuthError.service(exception.message ?? "Amazon Cognito cannot find a multi-factor authentication (MFA) method.", - AuthPluginErrorConstants.mfaMethodNotFoundError, - AWSCognitoAuthError.mfaMethodNotFound) - case .softwareTokenMFANotFoundException(let exception): - return AuthError.service(exception.message ?? "Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool.", - AuthPluginErrorConstants.softwareTokenNotFoundError, - AWSCognitoAuthError.softwareTokenMFANotEnabled) - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidLambdaResponseException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidSmsRoleAccessPolicyException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Access Policy error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole) - case .invalidSmsRoleTrustRelationshipException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Trust Relationship error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole) - case .invalidUserPoolConfigurationException(let exception): - return AuthError.configuration(exception.message ?? "Invalid UserPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authrozied error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return AuthError.service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userLambdaValidationException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userNotConfirmedException(let exception): - return AuthError.service(exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SdkError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SdkError+AuthError.swift deleted file mode 100644 index 5cea0f5d2e..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SdkError+AuthError.swift +++ /dev/null @@ -1,136 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import Amplify -import ClientRuntime - -extension SdkError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - - case .service(let serviceError, _): - if let authErrorMappable = serviceError as? AuthErrorConvertible { - return authErrorMappable.authError - } else if let otherError = serviceError as? Error { - return AuthError.service(otherError.localizedDescription, "", otherError) - } else { - return AuthError.unknown(String(describing: serviceError)) - } - case .client(let clientError, let httpResponse): - return convertToAuthError(clientError: clientError, httpResponse: httpResponse) - case .unknown(let unknownError): - return AuthError.unknown("An unknown error occured, check the underlying error for more details", - unknownError) - } - } - - func convertToAuthError(clientError: ClientError, - httpResponse: HttpResponse? = nil) -> AuthError { - switch clientError { - case .networkError(let error): - return AuthError.service(error.localizedDescription, - """ - Check your network connection, retry when the network is available. - HTTP Response stauts code: \(String(describing: httpResponse?.statusCode)) - """, - AWSCognitoAuthError.network) - - case .crtError(let cRTError): - return AuthError.service(cRTError.localizedDescription, - "Check the underlying error for more details", - cRTError) - - case .pathCreationFailed(let message): - return AuthError.service(message, "", clientError) - - case .queryItemCreationFailed(let message): - return AuthError.service(message, "", clientError) - - case .serializationFailed(let message): - return AuthError.service(message, "", clientError) - - case .deserializationFailed(let error): - return AuthError.service(error.localizedDescription, - "", - error) - - case .dataNotFound(let message): - return AuthError.service(message, "", clientError) - - case .authError(let message): - return AuthError.notAuthorized(message, "Check if you are authorized to perform the request") - - case .retryError(let error): - if let authError = error as? AuthErrorConvertible { - return authError.authError - } else { - return AuthError.service( - error.localizedDescription, - """ - Check your network connection, retry when the network is available. - HTTP Response stauts code: \(String(describing: httpResponse?.statusCode)) - """, - AWSCognitoAuthError.network) - - } - - case .unknownError(let message): - return AuthError.unknown(message, clientError) - } - } - -} - -extension Error { - func internalAWSServiceError() -> E? { - if let internalError = self as? E { - return internalError - } - - if let sdkError = self as? SdkError { - return sdkError.internalAWSServiceError() - } - return nil - } -} - -extension SdkError { - - func internalAWSServiceError() -> E? { - switch self { - - case .service(let error, _): - if let serviceError = error as? E { - return serviceError - } - - case .client(let clientError, _): - return clientError.internalAWSServiceError() - - default: break - - } - return nil - } -} - -extension ClientError { - - func internalAWSServiceError() -> E? { - switch self { - case .retryError(let retryError): - if let sdkError = retryError as? SdkError { - return sdkError.internalAWSServiceError() - } - - default: break - } - return nil - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SetUserMFAPreferenceOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SetUserMFAPreferenceOutputError+AuthError.swift deleted file mode 100644 index 0a58116414..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SetUserMFAPreferenceOutputError+AuthError.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import AWSCognitoIdentityProvider -import Amplify - -extension SetUserMFAPreferenceOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .internalErrorException(let exception): - return .unknown( - exception.message ?? "Internal exception occurred") - case .invalidParameterException(let exception): - return AuthError.service( - exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .notAuthorizedException(let exception): - return .notAuthorized( - exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return .service( - exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return .service( - exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .userNotConfirmedException(let userNotConfirmedException): - return .service( - userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return .service( - exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .forbiddenException(let forbiddenException): - return .service( - forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SignUpOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SignUpOutputError+AuthError.swift deleted file mode 100644 index dc530dc3b4..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/SignUpOutputError+AuthError.swift +++ /dev/null @@ -1,120 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Amplify -import Foundation -import AWSCognitoIdentityProvider - -extension SignUpOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .codeDeliveryFailureException(let exception): - - return .service( - exception.message ?? "Code Delivery Failure error", - AuthPluginErrorConstants.codeDeliveryError, - AWSCognitoAuthError.codeDelivery - ) - case .internalErrorException(let exception): - - return .unknown( - exception.message ?? "Internal exception occurred" - ) - case .invalidEmailRoleAccessPolicyException(let exception): - - return .service( - exception.message ?? "Invalid email role access policy error", - AuthPluginErrorConstants.invalidEmailRoleError, - AWSCognitoAuthError.emailRole - ) - case .invalidLambdaResponseException(let exception): - - return .service( - exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .invalidParameterException(let exception): - - return .service( - exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter - ) - case .invalidPasswordException(let exception): - - return .service( - exception.message ?? "Invalid password error", - AuthPluginErrorConstants.invalidPasswordError, - AWSCognitoAuthError.invalidPassword - ) - case .invalidSmsRoleAccessPolicyException(let exception): - - return .service( - exception.message ?? "Invalid SMS role access policy error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole - ) - case .invalidSmsRoleTrustRelationshipException(let exception): - - return .service( - exception.message ?? "Invalid SMS role access policy error", - AuthPluginErrorConstants.invalidSMSRoleError, - AWSCognitoAuthError.smsRole - ) - case .notAuthorizedException(let exception): - - return .notAuthorized( - exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .resourceNotFoundException(let exception): - - return .service( - exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound - ) - case .tooManyRequestsException(let exception): - - return .service( - exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded - ) - case .unexpectedLambdaException(let exception): - - return .service( - exception.message ?? "Unexpected lambda error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .userLambdaValidationException(let exception): - - return .service( - exception.message ?? "User lambda validation error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda - ) - case .usernameExistsException(let exception): - - return .service( - exception.message ?? "Username exists error", - AuthPluginErrorConstants.userNameExistsError, - AWSCognitoAuthError.usernameExists - ) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } - -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/UpdateDeviceStatusOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/UpdateDeviceStatusOutputError+AuthError.swift deleted file mode 100644 index 5df867d387..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/UpdateDeviceStatusOutputError+AuthError.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentityProvider -import Amplify - -extension UpdateDeviceStatusOutputError: AuthErrorConvertible { - - var authError: AuthError { - switch self { - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidUserPoolConfigurationException(let exception): - return .configuration(exception.message ?? "Invalid UserPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .notAuthorizedException(let exception): - return .notAuthorized(exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return .service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return .service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return .service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let userNotConfirmedException): - return .service(userNotConfirmedException.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return .service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/UpdateUserAttributesOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/UpdateUserAttributesOutputError+AuthError.swift deleted file mode 100644 index 2d68f8c446..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/UpdateUserAttributesOutputError+AuthError.swift +++ /dev/null @@ -1,96 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Foundation -import AWSCognitoIdentity -import Amplify -import AWSCognitoIdentityProvider - -extension UpdateUserAttributesOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .aliasExistsException(let exception): - return AuthError.service(exception.message ?? "An account with this email or phone already exists.", - AuthPluginErrorConstants.aliasExistsError, - AWSCognitoAuthError.aliasExists) - case .codeMismatchException(let exception): - return AuthError.service(exception.message ?? "Provided code does not match what the server was expecting.", - AuthPluginErrorConstants.codeMismatchError, - AWSCognitoAuthError.codeMismatch) - case .expiredCodeException(let exception): - return AuthError.service(exception.message ?? "Provided code has expired.", - AuthPluginErrorConstants.codeExpiredError, - AWSCognitoAuthError.codeExpired) - case .internalErrorException(let exception): - return .unknown(exception.message ?? "Internal exception occurred") - case .invalidLambdaResponseException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .invalidParameterException(let exception): - return AuthError.service(exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidSmsRoleAccessPolicyException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Access Policy error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.smsRole) - case .invalidSmsRoleTrustRelationshipException(let exception): - return AuthError.service(exception.message ?? "Invalid SMS Role Trust Relationship error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.smsRole) - case .notAuthorizedException(let exception): - return AuthError.notAuthorized(exception.message ?? "Not authrozied error", - AuthPluginErrorConstants.notAuthorizedError) - case .passwordResetRequiredException(let exception): - return AuthError.service(exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let exception): - return AuthError.service(exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service(exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .unexpectedLambdaException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userLambdaValidationException(let exception): - return AuthError.service(exception.message ?? "Invalid lambda response error", - AuthPluginErrorConstants.lambdaError, - AWSCognitoAuthError.lambda) - case .userNotConfirmedException(let exception): - return AuthError.service(exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service(exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - case .codeDeliveryFailureException(let exception): - return .service(exception.message ?? "Code Delivery Failure error", - AuthPluginErrorConstants.codeDeliveryError, - AWSCognitoAuthError.codeDelivery) - case .invalidEmailRoleAccessPolicyException(let exception): - return .service(exception.message ?? "Invalid email role access policy error", - AuthPluginErrorConstants.invalidEmailRoleError, - AWSCognitoAuthError.emailRole) - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } - -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifySoftwareTokenOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifySoftwareTokenOutputError+AuthError.swift deleted file mode 100644 index d7b56959ad..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifySoftwareTokenOutputError+AuthError.swift +++ /dev/null @@ -1,81 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Amplify -import AWSCognitoIdentityProvider - -extension VerifySoftwareTokenOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .codeMismatchException(let exception): - return AuthError.service( - exception.message ?? "Provided code does not match what the server was expecting.", - AuthPluginErrorConstants.codeMismatchError, - AWSCognitoAuthError.codeMismatch) - case .enableSoftwareTokenMFAException(let exception): - return AuthError.service( - exception.message ?? "Unable to enable software token MFA", - AuthPluginErrorConstants.softwareTokenNotFoundError, - AWSCognitoAuthError.softwareTokenMFANotEnabled) - case .forbiddenException(let forbiddenException): - return .service( - forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - case .internalErrorException(let internalErrorException): - return .unknown( - internalErrorException.message ?? "Internal exception occurred") - case .invalidParameterException(let invalidParameterException): - return .service( - invalidParameterException.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter) - case .invalidUserPoolConfigurationException(let exception): - return .configuration( - exception.message ?? "Invalid UserPool Configuration error", - AuthPluginErrorConstants.configurationError) - case .notAuthorizedException(let notAuthorizedException): - return .notAuthorized( - notAuthorizedException.message ?? "Not authorized Error", - AuthPluginErrorConstants.notAuthorizedError, - nil) - case .passwordResetRequiredException(let exception): - return AuthError.service( - exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired) - case .resourceNotFoundException(let resourceNotFoundException): - return AuthError.service( - resourceNotFoundException.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound) - case .softwareTokenMFANotFoundException(let exception): - return AuthError.service( - exception.message ?? "Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool.", - AuthPluginErrorConstants.softwareTokenNotFoundError, - AWSCognitoAuthError.mfaMethodNotFound) - case .tooManyRequestsException(let exception): - return AuthError.service( - exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded) - case .userNotConfirmedException(let exception): - return AuthError.service( - exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed) - case .userNotFoundException(let exception): - return AuthError.service( - exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound) - case .unknown(let unknownAWSHttpServiceError): - let statusCode = unknownAWSHttpServiceError._statusCode?.rawValue ?? -1 - let message = unknownAWSHttpServiceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifyUserAttributeOutputError+AuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifyUserAttributeOutputError+AuthError.swift deleted file mode 100644 index 812e6b71ce..0000000000 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifyUserAttributeOutputError+AuthError.swift +++ /dev/null @@ -1,105 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import Amplify -import Foundation -import AWSCognitoIdentityProvider - -extension VerifyUserAttributeOutputError: AuthErrorConvertible { - var authError: AuthError { - switch self { - case .codeMismatchException(let exception): - - return .service( - exception.message ?? "Code mismatch error", - AuthPluginErrorConstants.codeMismatchError, - AWSCognitoAuthError.codeMismatch - ) - case .expiredCodeException(let exception): - - return .service( - exception.message ?? "Expired code error", - AuthPluginErrorConstants.codeExpiredError, - AWSCognitoAuthError.codeExpired - ) - case .limitExceededException(let exception): - - return .service( - exception.message ?? "Limit exceeded error", - AuthPluginErrorConstants.limitExceededError, - AWSCognitoAuthError.limitExceeded - ) - case .userNotFoundException(let exception): - - return .service( - exception.message ?? "User not found error", - AuthPluginErrorConstants.userNotFoundError, - AWSCognitoAuthError.userNotFound - ) - case .internalErrorException(let exception): - - return .unknown( - exception.message ?? "Internal exception occurred" - ) - case .invalidParameterException(let exception): - - return .service( - exception.message ?? "Invalid parameter error", - AuthPluginErrorConstants.invalidParameterError, - AWSCognitoAuthError.invalidParameter - ) - case .notAuthorizedException(let exception): - - return .notAuthorized( - exception.message ?? "Not authorized error", - AuthPluginErrorConstants.notAuthorizedError - ) - case .resourceNotFoundException(let exception): - - return .service( - exception.message ?? "Resource not found error", - AuthPluginErrorConstants.resourceNotFoundError, - AWSCognitoAuthError.resourceNotFound - ) - case .tooManyRequestsException(let exception): - - return .service( - exception.message ?? "Too many requests error", - AuthPluginErrorConstants.tooManyRequestError, - AWSCognitoAuthError.requestLimitExceeded - ) - - case .unknown(let serviceError): - let statusCode = serviceError._statusCode?.rawValue ?? -1 - let message = serviceError._message ?? "" - return .unknown("Unknown service error occurred with status \(statusCode) \(message)") - - case .passwordResetRequiredException(let exception): - return .service( - exception.message ?? "Password reset required error", - AuthPluginErrorConstants.passwordResetRequired, - AWSCognitoAuthError.passwordResetRequired - ) - - case .userNotConfirmedException(let exception): - return AuthError.service( - exception.message ?? "User not confirmed error", - AuthPluginErrorConstants.userNotConfirmedError, - AWSCognitoAuthError.userNotConfirmed - ) - case .aliasExistsException(let exception): - return AuthError.service( - exception.message ?? "An account with this email or phone already exists.", - AuthPluginErrorConstants.aliasExistsError, - AWSCognitoAuthError.aliasExists) - - case .forbiddenException(let forbiddenException): - return .service(forbiddenException.message ?? "Access to the requested resource is forbidden", - AuthPluginErrorConstants.forbiddenError) - } - } -} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/SdkTypealiases.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/SdkTypealiases.swift index 28d19fa107..c4328aac58 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/SdkTypealiases.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/SdkTypealiases.swift @@ -9,6 +9,4 @@ import Foundation import AWSClientRuntime import ClientRuntime -public typealias SdkResult = Result> - public typealias NetworkResult = (Result) -> Void diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift index 9cec199958..31b7d6b12e 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift @@ -15,47 +15,19 @@ extension SignInError { var isUserNotConfirmed: Bool { switch self { case .service(error: let serviceError): - - if let internalError: InitiateAuthOutputError = serviceError.internalAWSServiceError(), - case .userNotConfirmedException = internalError { - return true - } - - if let internalError: RespondToAuthChallengeOutputError = serviceError.internalAWSServiceError(), - case .userNotConfirmedException = internalError { - return true - } - - if let internalError: VerifySoftwareTokenOutputError = serviceError.internalAWSServiceError(), - case .userNotConfirmedException = internalError { - return true - } - - default: break + return serviceError is AWSCognitoIdentityProvider.UserNotConfirmedException + default: + return false } - return false } var isResetPassword: Bool { switch self { case .service(error: let serviceError): - if let internalError: InitiateAuthOutputError = serviceError.internalAWSServiceError(), - case .passwordResetRequiredException = internalError { - return true - } - - if let internalError: RespondToAuthChallengeOutputError = serviceError.internalAWSServiceError(), - case .passwordResetRequiredException = internalError { - return true - } - - if let internalError: VerifySoftwareTokenOutputError = serviceError.internalAWSServiceError(), - case .passwordResetRequiredException = internalError { - return true - } - default: break + return serviceError is AWSCognitoIdentityProvider.PasswordResetRequiredException + default: + return false } - return false } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift index 32b7da1c83..ad3987d7f4 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift @@ -41,10 +41,12 @@ class AWSAuthChangePasswordTask: AuthChangePasswordTask, DefaultLogger { log.verbose("Received success") } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { - throw AuthError.configuration("Unable to execute auth task", AuthPluginErrorConstants.configurationError, error) + } catch { + throw AuthError.configuration( + "Unable to execute auth task", + AuthPluginErrorConstants.configurationError, + error + ) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift index d8b485acb0..bd9c8e0bc4 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift @@ -36,9 +36,7 @@ class AWSAuthConfirmResetPasswordTask: AuthConfirmResetPasswordTask, DefaultLogg try await confirmResetPassword() } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift index db0148eea5..962ae5c95a 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift @@ -42,16 +42,14 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger { _ = try await client.confirmSignUp(input: input) log.verbose("Received success") return AuthSignUpResult(.done, userID: nil) - } catch let error as AuthError { - throw error - } catch let error as AuthErrorConvertible { + } catch let error as AuthErrorConvertible { throw error.authError - } catch let error { - let error = AuthError.configuration( + } catch { + throw AuthError.configuration( "Unable to create a Swift SDK user pool service", AuthPluginErrorConstants.configurationError, - error) - throw error + error + ) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift index a39373f944..44b1836d24 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift @@ -38,9 +38,7 @@ class AWSAuthResendSignUpCodeTask: AuthResendSignUpCodeTask, DefaultLogger { return details } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResetPasswordTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResetPasswordTask.swift index 47b52040c0..a8bb33034e 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResetPasswordTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResetPasswordTask.swift @@ -38,9 +38,7 @@ class AWSAuthResetPasswordTask: AuthResetPasswordTask, DefaultLogger { return result } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignUpTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignUpTask.swift index 6400464697..485663d3d8 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignUpTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignUpTask.swift @@ -52,16 +52,14 @@ class AWSAuthSignUpTask: AuthSignUpTask, DefaultLogger { let response = try await client.signUp(input: input) log.verbose("Received result") return response.authResponse - } catch let error as AuthError { - throw error } catch let error as AuthErrorConvertible { throw error.authError - } catch let error { - let error = AuthError.configuration( + } catch { + throw AuthError.configuration( "Unable to create a Swift SDK user pool service", AuthPluginErrorConstants.configurationError, - error) - throw error + error + ) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift index 9e48e9f2f0..be7690da99 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift @@ -41,11 +41,9 @@ class AWSAuthWebUISignInTask: AuthWebUISignInTask, DefaultLogger { return result } catch let autherror as AuthErrorConvertible { throw autherror.authError - } catch let autherror as AuthError { - throw autherror - } catch let error { - let error = AuthError.unknown("Not able to signIn to the webUI", error) - throw error + } catch { + throw AuthError.unknown("Not able to signIn to the webUI", error) + } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift index 008b3647c1..b3a456214d 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift @@ -46,9 +46,7 @@ class FetchMFAPreferenceTask: AuthFetchMFAPreferenceTask, DefaultLogger { return try await fetchMFAPreference(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/SetUpTOTPTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/SetUpTOTPTask.swift index 78d90b3b6b..6a7ab2b6ea 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/SetUpTOTPTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/SetUpTOTPTask.swift @@ -37,9 +37,7 @@ class SetUpTOTPTask: AuthSetUpTOTPTask, DefaultLogger { return try await setUpTOTP(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UpdateMFAPreferenceTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UpdateMFAPreferenceTask.swift index de0774fb7a..b9bedf4fe8 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UpdateMFAPreferenceTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UpdateMFAPreferenceTask.swift @@ -52,9 +52,7 @@ class UpdateMFAPreferenceTask: AuthUpdateMFAPreferenceTask, DefaultLogger { return try await updateMFAPreference(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift index b169211da5..66796374ef 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift @@ -37,12 +37,12 @@ class AWSAuthAttributeResendConfirmationCodeTask: AuthAttributeResendConfirmatio return devices } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { - throw AuthError.configuration("Unable to execute auth task", - AuthPluginErrorConstants.configurationError, - error) + } catch { + throw AuthError.configuration( + "Unable to execute auth task", + AuthPluginErrorConstants.configurationError, + error + ) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthConfirmUserAttributeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthConfirmUserAttributeTask.swift index 390f15a2c2..8ed94106df 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthConfirmUserAttributeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthConfirmUserAttributeTask.swift @@ -37,9 +37,7 @@ class AWSAuthConfirmUserAttributeTask: AuthConfirmUserAttributeTask { try await confirmUserAttribute(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthFetchUserAttributeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthFetchUserAttributeTask.swift index 5a4ce680a0..cf15cc9395 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthFetchUserAttributeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthFetchUserAttributeTask.swift @@ -37,9 +37,7 @@ class AWSAuthFetchUserAttributeTask: AuthFetchUserAttributeTask { return try await getUserAttributes(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributeTask.swift index e0f6b9c386..9b25a406bf 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributeTask.swift @@ -36,11 +36,8 @@ class AWSAuthUpdateUserAttributeTask: AuthUpdateUserAttributeTask { return try await updateUserAttribute(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { - let error = AuthError.unknown("Unable to execute auth task", error) - throw error + } catch { + throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributesTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributesTask.swift index 30879838b4..0b0b8ed3dd 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributesTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthUpdateUserAttributesTask.swift @@ -36,9 +36,7 @@ class AWSAuthUpdateUserAttributesTask: AuthUpdateUserAttributesTask { return try await updateUserAttribute(with: accessToken) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift index 38d49134b4..40156b2e12 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift @@ -41,9 +41,7 @@ class VerifyTOTPSetupTask: AuthVerifyTOTPSetupTask, DefaultLogger { with: accessToken, userCode: request.code) } catch let error as AuthErrorConvertible { throw error.authError - } catch let error as AuthError { - throw error - } catch let error { + } catch { throw AuthError.unknown("Unable to execute auth task", error) } }