-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(analytics): update error handling (#3261)
- Loading branch information
Showing
14 changed files
with
238 additions
and
260 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
.../Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Extensions/SdkError+Analytics.swift
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...rces/AWSPinpointAnalyticsPlugin/Support/Utils/AWSPinpoint+AnalyticsErrorConvertible.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import Amplify | ||
import AWSPinpoint | ||
import ClientRuntime | ||
|
||
extension AWSPinpoint.BadRequestException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} | ||
|
||
extension AWSPinpoint.ForbiddenException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} | ||
|
||
extension AWSPinpoint.InternalServerErrorException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} | ||
|
||
extension AWSPinpoint.MethodNotAllowedException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} | ||
|
||
extension AWSPinpoint.NotFoundException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} | ||
|
||
extension AWSPinpoint.PayloadTooLargeException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} | ||
|
||
extension AWSPinpoint.TooManyRequestsException: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
.unknown(properties.message ?? "", self) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...nalytics/Sources/AWSPinpointAnalyticsPlugin/Support/Utils/AnalyticsErrorConvertible.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import Amplify | ||
|
||
protocol AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { get } | ||
} | ||
|
||
extension AnalyticsError: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...SPinpointAnalyticsPlugin/Support/Utils/CommonRunTimeError+AnalyticsErrorConvertible.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import Amplify | ||
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint | ||
import AwsCommonRuntimeKit | ||
|
||
extension CommonRunTimeError: AnalyticsErrorConvertible { | ||
var analyticsError: AnalyticsError { | ||
switch self { | ||
case .crtError(let crtError): | ||
let errorDescription = isConnectivityError | ||
? AWSPinpointErrorConstants.deviceOffline.errorDescription | ||
: crtError.message | ||
return .unknown(errorDescription, self) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/ClientError+IsRetryable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import ClientRuntime | ||
import Foundation | ||
|
||
extension ClientError { | ||
// TODO: Should some of these really be retried? | ||
var isRetryable: Bool { | ||
switch self { | ||
case .authError: | ||
return true | ||
case .dataNotFound: | ||
return true | ||
case .pathCreationFailed: | ||
return true | ||
case .queryItemCreationFailed: | ||
return true | ||
case .serializationFailed: | ||
return false | ||
case .unknownError: | ||
return true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/SdkError+IsRetryable.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ernal/Sources/InternalAWSPinpoint/Extensions/CommonRunTimeError+isConnectivityError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Amplify | ||
import AwsCIo | ||
import AwsCHttp | ||
import AwsCommonRuntimeKit | ||
import AWSPinpoint | ||
import ClientRuntime | ||
import Foundation | ||
|
||
@_spi(InternalAWSPinpoint) | ||
extension CommonRunTimeError { | ||
static let connectivityErrorCodes: Set<UInt32> = [ | ||
AWS_ERROR_HTTP_CONNECTION_CLOSED.rawValue, | ||
AWS_ERROR_HTTP_SERVER_CLOSED.rawValue, | ||
AWS_IO_DNS_INVALID_NAME.rawValue, | ||
AWS_IO_DNS_NO_ADDRESS_FOR_HOST.rawValue, | ||
AWS_IO_DNS_QUERY_FAILED.rawValue, | ||
AWS_IO_SOCKET_CONNECT_ABORTED.rawValue, | ||
AWS_IO_SOCKET_CONNECTION_REFUSED.rawValue, | ||
AWS_IO_SOCKET_CLOSED.rawValue, | ||
AWS_IO_SOCKET_NETWORK_DOWN.rawValue, | ||
AWS_IO_SOCKET_NO_ROUTE_TO_HOST.rawValue, | ||
AWS_IO_SOCKET_NOT_CONNECTED.rawValue, | ||
AWS_IO_SOCKET_TIMEOUT.rawValue, | ||
AWS_IO_TLS_NEGOTIATION_TIMEOUT.rawValue, | ||
UInt32(AWS_HTTP_STATUS_CODE_408_REQUEST_TIMEOUT.rawValue) | ||
] | ||
|
||
public var isConnectivityError: Bool { | ||
switch self { | ||
case .crtError(let error): | ||
Self.connectivityErrorCodes.contains(UInt32(error.code)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.