diff --git a/PACECloudSDK/API/Fueling/Generated/FuelingAPIClient.swift b/PACECloudSDK/API/Fueling/Generated/FuelingAPIClient.swift index cbff6f07..1f9c34e9 100644 --- a/PACECloudSDK/API/Fueling/Generated/FuelingAPIClient.swift +++ b/PACECloudSDK/API/Fueling/Generated/FuelingAPIClient.swift @@ -93,10 +93,12 @@ public class FuelingAPIClient { IDKit.refreshToken { [weak self] result in guard let self else { return } guard case let .failure(error) = result else { - guard case let .success(accessToken) = result, - let accessToken else { return } - urlRequest.setValue("Bearer \(accessToken)", - forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + guard case let .success(accessToken) = result else { return } + if let accessToken { + urlRequest.setValue("Bearer \(accessToken)", + forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + } + self.validateNetworkRequest(request: request, urlRequest: urlRequest, cancellableRequest: cancellableRequest, @@ -107,45 +109,42 @@ public class FuelingAPIClient { complete: complete) return } - + if case .failedTokenRefresh = error { completionQueue.async { let response = FuelingAPIResponse(request: request, - result: .failure(APIClientError - .unexpectedStatusCode(statusCode: 401, - data: Data("UNAUTHORIZED".utf8)))) + result: .failure(APIClientError + .unexpectedStatusCode(statusCode: 401, + data: Data("UNAUTHORIZED".utf8)))) complete(response) } } else { completionQueue.async { let response = FuelingAPIResponse(request: request, - result: .failure(APIClientError.unknownError(error))) + result: .failure(APIClientError.unknownError(error))) complete(response) } } } - } else if let accessToken = API.accessToken { + + return cancellableRequest + + } + + if let accessToken = API.accessToken { urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) - self.validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } - } else { - validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } + + validateNetworkRequest(request: request, + urlRequest: urlRequest, + cancellableRequest: cancellableRequest, + requestBehaviour: requestBehaviour, + currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, + currentRetryCount: currentRetryCount, + completionQueue: completionQueue, + complete: complete) return cancellableRequest } diff --git a/PACECloudSDK/API/POI/Generated/POIAPIClient.swift b/PACECloudSDK/API/POI/Generated/POIAPIClient.swift index 257ed11c..63fd166a 100644 --- a/PACECloudSDK/API/POI/Generated/POIAPIClient.swift +++ b/PACECloudSDK/API/POI/Generated/POIAPIClient.swift @@ -93,10 +93,12 @@ public class POIAPIClient { IDKit.refreshToken { [weak self] result in guard let self else { return } guard case let .failure(error) = result else { - guard case let .success(accessToken) = result, - let accessToken else { return } - urlRequest.setValue("Bearer \(accessToken)", - forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + guard case let .success(accessToken) = result else { return } + if let accessToken { + urlRequest.setValue("Bearer \(accessToken)", + forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + } + self.validateNetworkRequest(request: request, urlRequest: urlRequest, cancellableRequest: cancellableRequest, @@ -107,45 +109,42 @@ public class POIAPIClient { complete: complete) return } - + if case .failedTokenRefresh = error { completionQueue.async { let response = POIAPIResponse(request: request, - result: .failure(APIClientError - .unexpectedStatusCode(statusCode: 401, - data: Data("UNAUTHORIZED".utf8)))) + result: .failure(APIClientError + .unexpectedStatusCode(statusCode: 401, + data: Data("UNAUTHORIZED".utf8)))) complete(response) } } else { completionQueue.async { let response = POIAPIResponse(request: request, - result: .failure(APIClientError.unknownError(error))) + result: .failure(APIClientError.unknownError(error))) complete(response) } } } - } else if let accessToken = API.accessToken { + + return cancellableRequest + + } + + if let accessToken = API.accessToken { urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) - self.validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } - } else { - validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } + + validateNetworkRequest(request: request, + urlRequest: urlRequest, + cancellableRequest: cancellableRequest, + requestBehaviour: requestBehaviour, + currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, + currentRetryCount: currentRetryCount, + completionQueue: completionQueue, + complete: complete) return cancellableRequest } diff --git a/PACECloudSDK/API/Pay/Generated/PayAPIClient.swift b/PACECloudSDK/API/Pay/Generated/PayAPIClient.swift index 48610341..ead3e2a1 100644 --- a/PACECloudSDK/API/Pay/Generated/PayAPIClient.swift +++ b/PACECloudSDK/API/Pay/Generated/PayAPIClient.swift @@ -93,10 +93,12 @@ public class PayAPIClient { IDKit.refreshToken { [weak self] result in guard let self else { return } guard case let .failure(error) = result else { - guard case let .success(accessToken) = result, - let accessToken else { return } - urlRequest.setValue("Bearer \(accessToken)", - forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + guard case let .success(accessToken) = result else { return } + if let accessToken { + urlRequest.setValue("Bearer \(accessToken)", + forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + } + self.validateNetworkRequest(request: request, urlRequest: urlRequest, cancellableRequest: cancellableRequest, @@ -107,45 +109,42 @@ public class PayAPIClient { complete: complete) return } - + if case .failedTokenRefresh = error { completionQueue.async { let response = PayAPIResponse(request: request, - result: .failure(APIClientError - .unexpectedStatusCode(statusCode: 401, - data: Data("UNAUTHORIZED".utf8)))) + result: .failure(APIClientError + .unexpectedStatusCode(statusCode: 401, + data: Data("UNAUTHORIZED".utf8)))) complete(response) } } else { completionQueue.async { let response = PayAPIResponse(request: request, - result: .failure(APIClientError.unknownError(error))) + result: .failure(APIClientError.unknownError(error))) complete(response) } } } - } else if let accessToken = API.accessToken { + + return cancellableRequest + + } + + if let accessToken = API.accessToken { urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) - self.validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } - } else { - validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } + + validateNetworkRequest(request: request, + urlRequest: urlRequest, + cancellableRequest: cancellableRequest, + requestBehaviour: requestBehaviour, + currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, + currentRetryCount: currentRetryCount, + completionQueue: completionQueue, + complete: complete) return cancellableRequest } diff --git a/PACECloudSDK/API/User/Generated/UserAPIClient.swift b/PACECloudSDK/API/User/Generated/UserAPIClient.swift index 434a4fa1..ec024fd1 100644 --- a/PACECloudSDK/API/User/Generated/UserAPIClient.swift +++ b/PACECloudSDK/API/User/Generated/UserAPIClient.swift @@ -93,10 +93,12 @@ public class UserAPIClient { IDKit.refreshToken { [weak self] result in guard let self else { return } guard case let .failure(error) = result else { - guard case let .success(accessToken) = result, - let accessToken else { return } - urlRequest.setValue("Bearer \(accessToken)", - forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + guard case let .success(accessToken) = result else { return } + if let accessToken { + urlRequest.setValue("Bearer \(accessToken)", + forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) + } + self.validateNetworkRequest(request: request, urlRequest: urlRequest, cancellableRequest: cancellableRequest, @@ -107,45 +109,42 @@ public class UserAPIClient { complete: complete) return } - + if case .failedTokenRefresh = error { completionQueue.async { let response = UserAPIResponse(request: request, - result: .failure(APIClientError - .unexpectedStatusCode(statusCode: 401, - data: Data("UNAUTHORIZED".utf8)))) + result: .failure(APIClientError + .unexpectedStatusCode(statusCode: 401, + data: Data("UNAUTHORIZED".utf8)))) complete(response) } } else { completionQueue.async { let response = UserAPIResponse(request: request, - result: .failure(APIClientError.unknownError(error))) + result: .failure(APIClientError.unknownError(error))) complete(response) } } } - } else if let accessToken = API.accessToken { + + return cancellableRequest + + } + + if let accessToken = API.accessToken { urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: HttpHeaderFields.authorization.rawValue) - self.validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } - } else { - validateNetworkRequest(request: request, - urlRequest: urlRequest, - cancellableRequest: cancellableRequest, - requestBehaviour: requestBehaviour, - currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, - currentRetryCount: currentRetryCount, - completionQueue: completionQueue, - complete: complete) } + + validateNetworkRequest(request: request, + urlRequest: urlRequest, + cancellableRequest: cancellableRequest, + requestBehaviour: requestBehaviour, + currentUnauthorizedRetryCount: currentUnauthorizedRetryCount, + currentRetryCount: currentRetryCount, + completionQueue: completionQueue, + complete: complete) return cancellableRequest }