-
Notifications
You must be signed in to change notification settings - Fork 227
fix(Predictions): Callback is not triggered with URLError #896
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #896 +/- ##
==========================================
+ Coverage 67.29% 67.35% +0.06%
==========================================
Files 895 895
Lines 35389 35448 +59
==========================================
+ Hits 23814 23875 +61
+ Misses 11575 11573 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
.../Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Transcribe.swift
Outdated
Show resolved
Hide resolved
| self.clientDelegate.connectionStatusDidChange(status, withError: error) | ||
| } | ||
|
|
||
| guard nsError?.domain != NSURLErrorDomain else { |
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.
If the error is of type NSURLErrorDomain, we do not want to keep calling listen(), we should just return.
Probably
nsError?.code == -1003
should also be checked? https://stackoverflow.com/questions/27258702/error-domain-nsurlerrordomain-code-1003-a-server-with-the-specified-hostname-c
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.
Let's not use -1003 as a literal, though. Use the appropriate error code
.../Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Transcribe.swift
Outdated
Show resolved
Hide resolved
.../Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Transcribe.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/NativeWebSocketProvider.swift
Outdated
Show resolved
Hide resolved
palpatim
left a comment
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.
Comments below. Do you have unit tests to cover this case?
.../Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Transcribe.swift
Outdated
Show resolved
Hide resolved
| switch result { | ||
| case .failure(let error): | ||
| let status = AWSTranscribeStreamingClientConnectionStatus.closed | ||
| let nsError = error as NSError? |
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.
Error isn't nil, so you should be able to do let nsError = error as NSError, and do away with the optional chaining. My recollection is that Swift.Error always successfully casts to NSError
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.
Removing ? produces
'Error?' is not convertible to 'NSError'; did you mean to use 'as!' to force downcast?
and force cast is also not allowed.
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.
if you can't, i would go with
if let error = error as NSError? {
}
| self.clientDelegate.connectionStatusDidChange(status, withError: error) | ||
| } | ||
|
|
||
| guard nsError?.domain != NSURLErrorDomain else { |
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.
Let's not use -1003 as a literal, though. Use the appropriate error code
.../Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Transcribe.swift
Outdated
Show resolved
Hide resolved
| switch result { | ||
| case .failure(let error): | ||
| let status = AWSTranscribeStreamingClientConnectionStatus.closed | ||
| let nsError = error as NSError? |
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.
if you can't, i would go with
if let error = error as NSError? {
}
...ns/AWSPredictionsPluginTests/Service/PredictionsTest/PredictionsServiceTranscribeTests.swift
Outdated
Show resolved
Hide resolved
005deea to
b571032
Compare
AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/PredictionsErrorHelper.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/PredictionsErrorHelper.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/PredictionsErrorHelper.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/PredictionsErrorHelper.swift
Outdated
Show resolved
Hide resolved
...ns/AWSPredictionsPluginTests/Service/PredictionsTest/PredictionsServiceTranscribeTests.swift
Outdated
Show resolved
Hide resolved
…PredictionsErrorHelper.swift Co-authored-by: Michael Law <1365977+lawmicha@users.noreply.github.com>
...ns/AWSPredictionsPluginTests/Service/PredictionsTest/PredictionsServiceTranscribeTests.swift
Outdated
Show resolved
Hide resolved
.../Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Transcribe.swift
Outdated
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| static func mapError(_ error: NSError) -> PredictionsError { |
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.
case NSURLErorrDomain:
guard let urlError = error as? URLError else {
return defaultError
}
return .network(description, recovery, urlError)| case .completed(let result): | ||
| XCTFail("Should not produce result: \(result)") | ||
| case .failed(let error): | ||
| XCTAssertNotNil(error, "Should produce an error") |
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.
minor: assert it is a network error, then assert underlying error is .cannotFindHost
| } | ||
| return AWSTranscribeStreamingErrorMessage.map(errorType) ?? defaultError | ||
| case NSURLErrorDomain: | ||
| return mapError(error) |
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.
can cast to URLError now that you know it is NSURLErrorDomain, then call a specific method that takes in URLError as a parameter
| } | ||
| } | ||
|
|
||
| static func mapError(_ nsError: NSError) -> PredictionsError { |
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.
this is more like mapURLError(_ urlError: URLError)
Description of changes:
PR is a fix for #678
In the above cases, the Callback with error info is not triggered because it is skipping the error check.
The fix is:
listen()if is of type "NSURLErrorDomain".By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.