Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk update 0.22.0 error handling #3149

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct IAMURLRequestInterceptor: URLRequestInterceptor {
let requestBuilder = SdkHttpRequestBuilder()
.withHost(host)
.withPath(url.path)
.withQueryItems(queryItems)
.withQueryItems(queryItems.map { MyURLQueryItem(name: $0.name, value: $0.value)})
.withMethod(httpMethod)
.withPort(443)
.withProtocol(.https)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class IAMAuthInterceptor: AuthInterceptorAsync {
RealtimeProviderConstants.amzDate.lowercased(),
RealtimeProviderConstants.iamSecurityTokenKey.lowercased()]

let authProvider: CredentialsProvider
let authProvider: CredentialsProviding
let region: AWSRegionType

init(_ authProvider: CredentialsProvider, region: AWSRegionType) {
init(_ authProvider: CredentialsProviding, region: AWSRegionType) {
self.authProvider = authProvider
self.region = region
}
Expand Down Expand Up @@ -60,8 +60,8 @@ class IAMAuthInterceptor: AuthInterceptorAsync {
guard var urlComponents = URLComponents(url: request.url, resolvingAgainstBaseURL: false) else {
return request
}
let headerQuery = URLQueryItem(name: RealtimeProviderConstants.header, value: base64Auth)
let payloadQuery = URLQueryItem(name: RealtimeProviderConstants.payload, value: payloadBase64)
let headerQuery = Foundation.URLQueryItem(name: RealtimeProviderConstants.header, value: base64Auth)
let payloadQuery = Foundation.URLQueryItem(name: RealtimeProviderConstants.payload, value: payloadBase64)
urlComponents.queryItems = [headerQuery, payloadQuery]
guard let signedUrl = urlComponents.url else {
return request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ import ClientRuntime
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

extension SdkError {
//extension SdkError {
// var analyticsError: AnalyticsError {
// return .unknown(
// isConnectivityError ? AWSPinpointErrorConstants.deviceOffline.errorDescription : errorDescription,
// rootError ?? self
// )
// }
//}

extension ModeledError where Self: Error {
var analyticsError: AnalyticsError {
return .unknown(
isConnectivityError ? AWSPinpointErrorConstants.deviceOffline.errorDescription : errorDescription,
rootError ?? self
)
let description = /* isConnectivityError
? AWSPinpointErrorConstants.deviceOffline.errorDescription
: errorDescription
*/ ""
return .unknown(description, self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Foundation

class AnalyticsErrorHelper {
static func getDefaultError(_ error: Error) -> AnalyticsError {
if let sdkError = error as? SdkError<PutEventsOutputError>{
return sdkError.analyticsError
}
// if let sdkError = error as? SdkError<PutEventsOutputError>{
// return sdkError.analyticsError
// }

if let analyticsError = error as? AnalyticsError {
return analyticsError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/amplify-swift-utils-notifications.git",
"state" : {
"revision" : "c47cafce7c456b3f1f2cf6ef4863bf5e2340d9eb",
"version" : "0.0.1"
"revision" : "f970384ad1035732f99259255cd2f97564807e41",
"version" : "1.1.0"
}
},
{
"identity" : "aws-appsync-realtime-client-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/aws-appsync-realtime-client-ios.git",
"state" : {
"revision" : "da88cf1cab82e281e7277cd9feb9efc87a057041",
"version" : "2.1.1"
"revision" : "c7ec93dcbbcd8abc90c74203937f207a7fcaa611",
"version" : "3.1.1"
}
},
{
"identity" : "aws-crt-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-crt-swift",
"state" : {
"revision" : "afe23a2a2f6cf78e6d8803d7c9e0c8e6f50b6915",
"version" : "0.4.0"
}
},
{
"identity" : "aws-sdk-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-sdk-swift.git",
"state" : {
"revision" : "c54c028cfc3ee70fde8c077547a1a1f6ef1137d9",
"version" : "0.6.0"
"revision" : "838deb5de707f157986e4baa95439cbcac9f3fcf",
"version" : "0.12.0"
}
},
{
Expand All @@ -54,15 +45,6 @@
"version" : "2.1.0"
}
},
{
"identity" : "smithy-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/smithy-swift",
"state" : {
"revision" : "f59ed07c29d4e03f91ea8324edf7a2486bd86a9c",
"version" : "0.6.0"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -104,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/MaxDesiatov/XMLCoder.git",
"state" : {
"revision" : "ca932442d7481700f5434a7b138c47dd42d9902b",
"version" : "0.14.0"
"revision" : "80b4a1646399b8e4e0ce80711653476a85bd5e37",
"version" : "0.17.0"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "97914D16295641D3002000EA"
BlueprintIdentifier = "97914D2029564227002000EA"
BuildableName = "AnalyticsStressTests.xctest"
BlueprintName = "AnalyticsStressTests"
ReferencedContainer = "container:AnalyticsHostApp.xcodeproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ extension AWSCognitoAuthPlugin {
switch authConfiguration {
case .userPools(let userPoolConfig), .userPoolsAndIdentityPools(let userPoolConfig, _):
let configuration = try CognitoIdentityProviderClient.CognitoIdentityProviderClientConfiguration(
endpointResolver: userPoolConfig.endpoint?.resolver,
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(),
region: userPoolConfig.region
region: userPoolConfig.region,
serviceSpecific: .init(endpointResolver: userPoolConfig.endpoint?.resolver),
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData()
)

if var httpClientEngineProxy = httpClientEngineProxy {
Expand All @@ -108,8 +108,8 @@ extension AWSCognitoAuthPlugin {
switch authConfiguration {
case .identityPools(let identityPoolConfig), .userPoolsAndIdentityPools(_, let identityPoolConfig):
let configuration = try CognitoIdentityClient.CognitoIdentityClientConfiguration(
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(),
region: identityPoolConfig.region
region: identityPoolConfig.region,
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData()
)
return CognitoIdentityClient(config: configuration)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Loading