launchdarkly / swift-eventsource

Server-sent events (SSE) client implementation in Swift for iOS, macOS, tvOS, and watchOS
https://launchdarkly.github.io/swift-eventsource/
Other
196 stars 36 forks source link

Respect error handler's action for unsuccessful response errors #13

Closed tomasf closed 3 years ago

tomasf commented 3 years ago

Previous behavior

For UnsuccessfulResponseError, the error handler is consulted but its action is never used. The data task is then cancelled, leading to a URLError.cancelled error, and the error handler's action for this error is what is used for deciding the behavior. This is probably not what anyone expects or wants.

New behavior

If the error handler returns .shutdown for unsuccessful response errors, we set readyState to .shutdown. The error handler never gets the URLError.cancelled error and afterComplete() shuts down.

gwhelanLD commented 3 years ago

Hi @tomasf,

Thanks for the PR, this looks like a very reasonable change. I'm going to see about fixing the CI build in master (it appears circle removed the particular xcode we were using to test UA), and then we should be able to get this merged in.

Thanks, @gwhelanLD