title: Alamofire refreshToken with Retrier: how to get status of refreshToken request and reroute to LoginView
body: <p>I customize refreshTokens functions according to Alamofire <a href="https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#adapting-and-retrying-requests" rel="nofollow noreferrer">guide</a>.</p>
  
  <p>I'd like to reroute to Login View when refreshTokens failed and got 401 status from API server (for other error status like 400 or 500, just display error message in the view).
  Currently I use UserDefaults to notice 401 status to the view (, who call the Alamofire request).</p>
  
  <p>I'd like to know if there's better approach to notice "refreshToken status" to the view (or approach to share the status variable with view and oauth2handler).</p>
  
  <p>thanks!</p>
  
  <ul>
  <li><p>OAuth2Handler</p>
  
  <pre><code>    manager.request(urlString, method: .post, parameters: parameters, encoding: URLEncoding.default)
          .responseJSON { [weak self] response in
              guard let strongSelf = self else { return }
  
              if
                  let json = response.result.value as? [String: Any],
                  let accessToken = json["access_token"] as? String
              {
                  completion(true, accessToken)
              } else {
                  if let status = response.response?.statusCode, status == 401 {
                      UserDefaults.standard.set(true, forKey: "login_required")
  
                  }
                  completion(false, nil)
              }
  
              strongSelf.isRefreshing = false
      }
  </code></pre></li>
  <li><p>ViewController action when some button clicked</p>
  
  <pre><code>_ = client.request(API.addLike(json: comment))
      .subscribe(
          onSuccess: { (response) in
              // successful!
          },
          onError: { (err) in
              let loginRequired = UserDefaults.standard.bool(forKey: "login_required")
              if loginRequired == true {
                  print("refresh token is wrong or expired. login required")
                  // transition to LoginView
              } else {
                  print("request is invalid or server is down.")
              }
          }
      )
  </code></pre></li>
  </ul>