title: Alamofire RequestRetrier with timeout error handling
body: <p>I'm using <code>RequestRetrier</code> to automatically renew access_token for my API. But in each request function I would like to catch timeout error, but <code>.case(let error)</code> in <code>.responseJSON</code> body never executes, because of (I guess) <code>retrier</code> that I add to my <code>accessSessionManager</code>. Here's how it looks like: </p>
  
  <pre><code>lazy var accessSessionManager: SessionManager = {
      let configuration = URLSessionConfiguration.default
      configuration.timeoutIntervalForRequest = Configuration.timeout
      configuration.timeoutIntervalForResource = Configuration.timeout
      let sessionManager = Alamofire.SessionManager(configuration: configuration)
      let oAuth2Handler = OAuth2Handler()
      sessionManager.retrier = oAuth2Handler
      sessionManager.adapter = oAuth2Handler
      return sessionManager
  }()
  
  
  func changeName(newName: String,completionHandler: ((_ success: Bool, _ error: String?) -&gt; ())?) {
      guard let accessToken = self.getAccessToken() else { return }
      let parameters = ["access_token": accessToken,  "name": newName] as [String : Any]
      self.accessSessionManager.request(Constants.nameUrl, method: .get, parameters: parameters).responseJSON { response in
              switch response.result {
              case .success(let json):
                  let jsonDict = JSON(json)
                  if let success = jsonDict["success"].bool {
                      completionHandler?(success, nil)
                  }
  
              case .failure(let error):
                  if error._code == NSURLErrorTimedOut {
                      completionHandler?(false, "Please check your Internet connection and try again!")
                  } else if response.response?.statusCode == 400 {
                      completionHandler?(false, "Sorry, name not found")
                  } else if response.response?.statusCode != 401 {
                      completionHandler?(false, error.localizedDescription)
                  }
              }
          }
      }
  }
  
  ....
  ....
   class OAuth2Handler {
  
   //MARK: - Adapter
     func adapt(_ urlRequest: URLRequest) throws -&gt; URLRequest {
      if let url = urlRequest.url {
          guard let accessToken = self.getAccessToken() else { return  urlRequest }
          let newUrl = addOrUpdateQueryStringParameter(url: "\(url)", key: "access_token", value: accessToken)
          let newRequest = URLRequest(url: URL(string: newUrl)!)
          return newRequest
      }
  
      return urlRequest
  }
   // MARK: - RequestRetrier
    func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) {
      lock.lock() ; defer { lock.unlock() }
      if let response = request.task?.response as? HTTPURLResponse {
          if response.statusCode == 401 {
              requestsToRetry.append(completion)
              if !isRefreshing {
                  refreshTokens { [weak self] succeeded, accessToken, refreshToken in
                      guard let strongSelf = self else { return }
                      strongSelf.lock.lock() ; defer { strongSelf.lock.unlock() }
  
                      if let accessToken = accessToken, let refreshToken = refreshToken {
                          strongSelf.accessToken = accessToken
                          strongSelf.refreshToken = refreshToken
                          strongSelf.updateAccessToken(accessToken: accessToken, refreshToken: refreshToken)
                      }
                      strongSelf.requestsToRetry.forEach { $0(succeeded, 0.0) }
                      strongSelf.requestsToRetry.removeAll()
                  }
              }
          } else {
              completion(false, 0.0)
          }
      }
  }
  </code></pre>
  
  <p>So, basically error handling performs in <code>should</code> function, not in <code>.case(let error)</code> in my function.</p>