[PR #693] Improvements to requestWithAutomaticAccessTokenRenewal #721

Open
opened 2026-03-03 17:29:50 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/OAuthSwift/OAuthSwift/pull/693
Author: @vgritsenko
Created: 1/31/2022
Status: 🔄 Open

Base: masterHead: master


📝 Commits (1)

  • e3da86e Fix error handling and improve control flow in requestWithAutomaticAccessTokenRenewal.

📊 Changes

1 file changed (+16 additions, -27 deletions)

View changed files

📝 Sources/OAuthSwiftClient.swift (+16 -27)

📄 Description

This fixes error handling, and makes a couple of improvements to implementation of the requestWithAutomaticAccessTokenRenewal function:

  • Pass all error responses as-is, and look only for the tokenExpired;
  • Treat onTokenRenewal parameter as truly optional - perform the token renewal even if onTokenRenewal is nil;
  • Do not keep a strong reference to self in the completion block for renewAccessToken call.

The main issue I had was that requestWithAutomaticAccessTokenRenewal would swallow all errors and convert them to the empty tokenExpired errors, preventing any possibility of implementing custom error handling logic on the client side:

completion(.failure(.tokenExpired(error: nil)))

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/OAuthSwift/OAuthSwift/pull/693 **Author:** [@vgritsenko](https://github.com/vgritsenko) **Created:** 1/31/2022 **Status:** 🔄 Open **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`e3da86e`](https://github.com/OAuthSwift/OAuthSwift/commit/e3da86e06acf8a15e851a19f8fd9bb38fba844e4) Fix error handling and improve control flow in requestWithAutomaticAccessTokenRenewal. ### 📊 Changes **1 file changed** (+16 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `Sources/OAuthSwiftClient.swift` (+16 -27) </details> ### 📄 Description This fixes error handling, and makes a couple of improvements to implementation of the `requestWithAutomaticAccessTokenRenewal` function: - Pass all error responses as-is, and look only for the `tokenExpired`; - Treat `onTokenRenewal` parameter as truly optional - perform the token renewal even if `onTokenRenewal` is `nil`; - Do not keep a strong reference to `self` in the completion block for `renewAccessToken` call. The main issue I had was that `requestWithAutomaticAccessTokenRenewal` would swallow all errors and convert them to the empty `tokenExpired` errors, preventing any possibility of implementing custom error handling logic on the client side: ``` completion(.failure(.tokenExpired(error: nil))) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#721
No description provided.