-
Notifications
You must be signed in to change notification settings - Fork 32
/
URLRequestAuthenticator.swift
45 lines (40 loc) · 1.84 KB
/
URLRequestAuthenticator.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Foundation
#if canImport(AlicerceCore)
import AlicerceCore
#endif
// A type representing a request authenticator.
public protocol URLRequestAuthenticator: AnyObject {
/// The authenticator's authentication handler closure, invoked when a request's authentication finishes.
typealias AuthenticationHandler = (Result<URLRequest, Error>) -> Cancelable
/// Authenticates a request.
///
/// - Important: The cancelable returned by the `handler` closure *when called asynchronously* should be added
/// as a child of the cancelable returned by this method, so that the async work gets chained and can be cancelled.
///
/// - Parameters:
/// - request: The request to authenticate.
/// - handler: The closure to handle the request authentication's result (i.e. either the authenticated request
/// or an error).
///
/// - Returns: A cancelable to cancel the operation.
@discardableResult
func authenticateRequest(_ request: URLRequest, handler: @escaping AuthenticationHandler) -> Cancelable
/// Evaluates failed requests and determines which action to take from an authentication perspective.
/// - Parameters:
/// - request: The failed request.
/// - response: The failed request's response.
/// - payload: The failed request's payload.
/// - error: The failed request's error.
/// - retryState: The retry state, containing:
/// + errors that have occured so far (i.e. have resulted in a previous retry), excluding the current error.
/// + the total amount of delay that has been used on retries.
///
/// - Returns: The retry action to apply to the operation.
func evaluateFailedRequest(
_ request: URLRequest,
data: Data?,
response: URLResponse?,
error: Error,
retryState: Retry.State
) -> Retry.Action
}