title: Alamofire request interceptor not being called
body: <p>Adding to my litany of Alamofire SO posts this week, why doesnt my RequestInterceptor work? Nothing inside of the adapt function gets called however a breakpoint outside of either function is hit.</p>
  <p>Im starting to believe its not specifically the RequestInterceptor itself since I have copied a few different guides to see if it would break inside the functions and they do not.
  <a href="https://www.avanderlee.com/swift/authentication-alamofire-request-adapter/" rel="nofollow noreferrer">https://www.avanderlee.com/swift/authentication-alamofire-request-adapter/</a>
  <a href="https://www.raywenderlich.com/11668143-alamofire-tutorial-for-ios-advanced-usage#toc-anchor-013" rel="nofollow noreferrer">https://www.raywenderlich.com/11668143-alamofire-tutorial-for-ios-advanced-usage#toc-anchor-013</a>
  <a href="https://medium.com/swlh/retry-request-using-alamofire-52c7dcd72175" rel="nofollow noreferrer">https://medium.com/swlh/retry-request-using-alamofire-52c7dcd72175</a></p>
  <p>finally landed here and followed a few options there which have not helped the issue either.
  <a href="https://github.com/Alamofire/Alamofire/issues/2998" rel="nofollow noreferrer">https://github.com/Alamofire/Alamofire/issues/2998</a></p>
  <p>Here is my interceptor</p>
  <pre><code>import Alamofire
  
  class APIRequestInterceptor: RequestInterceptor {
      
      typealias AdapterResult = Swift.Result&lt;URLRequest, Error&gt;
    
      let retryLimit = 5
      let retryDelay: TimeInterval = 10
    
  //    func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Swift.Result&lt;URLRequest, Error&gt;) -&gt; Void) {
      func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AdapterResult) -&gt; Void) {
  //    func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result&lt;URLRequest, Error&gt;) -&gt; Void) {
  //    func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result&lt;URLRequest, AFError&gt;) -&gt; Void) {
          var urlRequest = urlRequest
          
          debugPrint(&quot;In the request interceptor...&quot;)
          debugPrint(urlRequest)
          
          if let token = Globals.sharedInstance.token {
              urlRequest.setValue(&quot;Bearer \(token)&quot;, forHTTPHeaderField: &quot;Authorization&quot;)
          }
          completion(.success(urlRequest))
      }
    
      func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -&gt; Void) {
          let response = request.task?.response as? HTTPURLResponse
          //Retry for 5xx status codes
          if
              let statusCode = response?.statusCode,
              (500...599).contains(statusCode),
              request.retryCount &lt; retryLimit {
              completion(.retryWithDelay(retryDelay))
          } else {
              return completion(.doNotRetry)
          }
      }
  }
  </code></pre>
  <p>and my client creating the session</p>
  <pre><code>static let sessionManager: Session = {
      let configuration = URLSessionConfiguration.af.default
      
      configuration.timeoutIntervalForRequest = 30
      configuration.waitsForConnectivity = true
      
      return Session(configuration: configuration, interceptor: APIRequestInterceptor(), eventMonitors: [APILogger()])
  }()
  </code></pre>
  <p>and to be thorough, the requests are being made using <code>sessionManager.request(convertible: URLRequestConvertible)</code></p>
  <p>Looking at the request function, not sure why an interceptor is defined again in the request parameters?
  <code>open func request(_ convertible: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -&gt; DataRequest {}</code>
  nevertheless I also tried defining it again in the request params without any luck. <code>sessionManager.request(route, interceptor: APIRequestInterceptor())</code></p>