-
Notifications
You must be signed in to change notification settings - Fork 202
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
fix(analytics): update error handling #3261
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why this was changed from class to enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I must've instinctively made that change without realizing it.
As a simple namespace, it should be an enum. That said, I don't mind reverting as it doesn't really belong in this PR.