Skip to content
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

Update readyState on urlSession error #146

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EventSource/EventSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ open class EventSource: NSObject, EventSourceProtocol, URLSessionDataDelegate {
open func urlSession(_ session: URLSession,
task: URLSessionTask,
didCompleteWithError error: Error?) {

readyState = .closed
guard let responseStatusCode = (task.response as? HTTPURLResponse)?.statusCode else {
mainQueue.async { [weak self] in self?.onComplete?(nil, nil, error as NSError?) }
return
Expand Down
3 changes: 3 additions & 0 deletions EventSourceTests/EventSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class EventSourceTests: XCTestCase {
func testOnCompleteRetryTrue() {
let expectation = XCTestExpectation(description: "onComplete gets called")
eventSource.onComplete { statusCode, retry, _ in
XCTAssertEqual(self.eventSource.readyState, .closed)
XCTAssertEqual(statusCode, 200)
XCTAssertEqual(retry, false)
expectation.fulfill()
Expand All @@ -103,6 +104,7 @@ class EventSourceTests: XCTestCase {
func testOnCompleteRetryFalse() {
let expectation = XCTestExpectation(description: "onComplete gets called")
eventSource.onComplete { statusCode, retry, _ in
XCTAssertEqual(self.eventSource.readyState, .closed)
XCTAssertEqual(statusCode, 250)
XCTAssertEqual(retry, true)
expectation.fulfill()
Expand All @@ -118,6 +120,7 @@ class EventSourceTests: XCTestCase {
func testOnCompleteError() {
let expectation = XCTestExpectation(description: "onComplete gets called")
eventSource.onComplete { statusCode, retry, error in
XCTAssertEqual(self.eventSource.readyState, .closed)
XCTAssertNotNil(error)
XCTAssertNil(retry)
XCTAssertNil(statusCode)
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "EventSource",
platforms: [
.iOS("8.0"),
.iOS("9.0"),
.macOS("10.10"),
],
products: [
Expand Down