Advertisement
McFamous

Untitled

Jan 25th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. final class CustomAuthenticationInterceptor: RequestInterceptor {
  2. let authenticationInterceptor: AuthenticationInterceptor<TokenResolver>
  3. var isEnabled = true
  4.  
  5. init(authenticator: TokenResolver) {
  6. self.authenticationInterceptor = AuthenticationInterceptor(authenticator: authenticator)
  7. }
  8.  
  9. func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) {
  10. if isEnabled {
  11. authenticationInterceptor.adapt(urlRequest, for: session, completion: completion)
  12. return
  13. }
  14. completion(.success(urlRequest))
  15. }
  16.  
  17. func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {
  18. if isEnabled {
  19. authenticationInterceptor.retry(request, for: session, dueTo: error, completion: completion)
  20. return
  21. }
  22. completion(.doNotRetry)
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement