SwiftHTTP icon indicating copy to clipboard operation
SwiftHTTP copied to clipboard

Retry a task?

Open valentinjahanmanesh opened this issue 6 years ago • 0 comments

is there any way to retry a task or i have to implement it by my self? i mean retry a task after receiving the response :

//handle task finishing
      public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
          guard let resp = responseForTask(task) else { return }
          resp.error = error as NSError?
          if let hresponse = task.response as? HTTPURLResponse {
            resp.headers = hresponse.allHeaderFields as? Dictionary<String,String>
            resp.mimeType = hresponse.mimeType
            resp.suggestedFilename = hresponse.suggestedFilename
            resp.statusCode = hresponse.statusCode
            resp.URL = hresponse.url
        }
        
        if let code = resp.statusCode, code > 299 {
            //-1001//
            resp.error = createError(code)
        }
        if let handler = resp.completionHandler {
            handler(resp)
        }
        
        removeTask(task)
    }

valentinjahanmanesh avatar Nov 03 '18 14:11 valentinjahanmanesh