Skip to content

Retry a task? #299

@valentinjahanmanesh

Description

@valentinjahanmanesh

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)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions