     }
     
     public func urlSession(_ session: URLSession, dataTask task: URLSessionDataTask, didReceive httpResponse: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
-        guard !isForcedClose(httpResponse as? HTTPURLResponse) else {
-            callback?.pyroEventSource(self, didReceiveError: PyroEventSourceError.forcedClose)
+        if let responseError = response.isErroneous(httpResponse as? HTTPURLResponse) {
             close()
-            return
-        }
-        
-        if let responseError = response.isErroneous(httpResponse as? HTTPURLResponse) {
             callback?.pyroEventSource(self, didReceiveError: responseError)
-            close()
             
         } else {
+            state = .open
             completionHandler(.allow)
-            state = .open
         }
     }
     
     public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
+        close()
+        
         guard !isForcedClose(task.response as? HTTPURLResponse) else {
             callback?.pyroEventSource(self, didReceiveError: PyroEventSourceError.forcedClose)
-            close()
             return
         }
         
         if let responseError = response.isErroneous(task.response as? HTTPURLResponse) {
             callback?.pyroEventSource(self, didReceiveError: responseError)
-            close()
-        
-        } else {
-            callback?.pyroEventSource(self, didReceiveError: error ?? RequestError.unknown)
         }
     }
 }

        }
        
        session = sessionProvider.createSession(for: self, lastEventID: lastEventID)
        session.dataTask(with: url).resume()
        state = .connecting
    }
    
    internal func isForcedClose(_ response: HTTPURLResponse?) -> Bool {

        }
        
        guard !isForcedClose(task.response as? HTTPURLResponse) else {
            close()
            callback?.pyroEventSource(self, didReceiveError: PyroEventSourceError.forcedClose)
            return
        }
        
        if let responseError = response.isErroneous(task.response as? HTTPURLResponse) {
            close()
            callback?.pyroEventSource(self, didReceiveError: responseError)
            
        } else {
            let message = parser.parse(data)
