Skip to content

Commit

Permalink
fix(datastore): propagate connectionLost URLError
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Aug 7, 2024
1 parent 179fa3f commit 7027a44
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
log.debug("[AppSyncRealTimeClient] start subscription failed, could not found subscription with id \(id) ")
throw APIError.unknown("Could not find a subscription with id \(id)", "", nil)
}
log.debug("[AppSyncRealTimeClient] current number of subscriptions: \(numberOfSubscriptions)")

try await subscription.subscribe()

return AnyCancellable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,7 @@ fileprivate func toAPIError<R: Decodable>(_ errors: [Error], type: R.Type) -> AP
)

case let errors as [WebSocketClient.Error]:
if errors.contains(where: { $0 == .connectionCancelled || $0 == .connectionLost}) {
return APIError.networkError("WebSocketClient connection aborted", nil, errors.first)
}
return APIError.operationError(
errorDescription(),
"",
errors.first
)
return APIError.networkError("WebSocketClient connection aborted", nil, URLError(.networkConnectionLost))
default:
return APIError.operationError(
errorDescription(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0
//


import Network
import Combine

Expand Down Expand Up @@ -38,6 +37,7 @@ public final class AmplifyNetworkMonitor {
label: "com.amazonaws.amplify.ios.network.websocket.monitor",
qos: .userInitiated
))

}

public func updateState(_ nextState: State) {
Expand All @@ -48,4 +48,5 @@ public final class AmplifyNetworkMonitor {
subject.send(completion: .finished)
monitor.cancel()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension RemoteSyncEngine {
}

func scheduleRestartOrTerminate(error: AmplifyError) {
Self.log.debug("scheduling restart or terminate on error: \(error)")
let advice = getRetryAdvice(error: error)
if advice.shouldRetry {
scheduleRestart(advice: advice)
Expand Down

0 comments on commit 7027a44

Please sign in to comment.