-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed AppSyncMQTTClient data races (#184)
- Added `statusChangeHandler` to AppSyncClient's `subscribe` method to provide status updates. - Added verbose logging around subscription connections - Cancel streams and reconnect threads on disconnect
- Loading branch information
Showing
17 changed files
with
1,446 additions
and
760 deletions.
There are no files selected for viewing
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
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
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,97 @@ | ||
// | ||
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// Licensed under the Amazon Software License | ||
// http://aws.amazon.com/asl/ | ||
// | ||
|
||
import Foundation | ||
|
||
public enum AWSAppSyncSubscriptionError: Error, LocalizedError { | ||
/// The underlying MQTT client reported a status of "connectionError" | ||
case connectionError | ||
|
||
/// The underlying MQTT client reported a status of "connectionRefused" | ||
case connectionRefused | ||
|
||
/// The underlying MQTT client reported a status of "disconnected" | ||
case disconnected | ||
|
||
/// An error occurred parsing the subscription message received from the service | ||
case messageCallbackError(String) | ||
|
||
/// Some other error occurred. See associated value for details | ||
case other(Error) | ||
|
||
/// An error occurred parsing the published subscription message | ||
case parseError(Error) | ||
|
||
/// The underlying MQTT client reported a status of "protocolError" | ||
case protocolError | ||
|
||
/// An error occurred while making the initial subscription request to AppSync, parsing its response, or | ||
/// evaluating the response's subscription info payload | ||
case setupError(String) | ||
|
||
/// The underlying MQTT client reported a status of "unknown" | ||
case unknownMQTTConnectionStatus | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .messageCallbackError(let message): | ||
return message | ||
case .other(let error): | ||
return error.localizedDescription | ||
case .parseError(let error): | ||
return error.localizedDescription | ||
case .setupError(let message): | ||
return message | ||
case .unknownMQTTConnectionStatus: | ||
return "MQTT status unknown" | ||
default: | ||
return "Subscription Terminated." | ||
} | ||
} | ||
|
||
public var recoverySuggestion: String? { | ||
switch self { | ||
case .other(let error as NSError): | ||
return error.localizedRecoverySuggestion | ||
case .parseError, .unknownMQTTConnectionStatus: | ||
return nil | ||
default: | ||
return "Restart subscription request." | ||
} | ||
} | ||
|
||
public var failureReason: String? { | ||
switch self { | ||
case .other(let error as NSError): | ||
return error.localizedFailureReason | ||
case .parseError, .unknownMQTTConnectionStatus: | ||
return nil | ||
case .setupError(let message): | ||
return message | ||
default: | ||
return "Disconnected from service." | ||
} | ||
} | ||
} | ||
|
||
extension AWSAppSyncSubscriptionError { | ||
static func from(status: AWSIoTMQTTStatus) -> AWSAppSyncSubscriptionError? { | ||
switch status { | ||
case .connectionError: | ||
return .connectionError | ||
case .connectionRefused: | ||
return .connectionRefused | ||
case .disconnected: | ||
return .disconnected | ||
case .protocolError: | ||
return .protocolError | ||
case .unknown: | ||
return .unknownMQTTConnectionStatus | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
Oops, something went wrong.