From e7999286d5a3083e64b060be8a1a768835898d4e Mon Sep 17 00:00:00 2001 From: Zach Jaquish Date: Tue, 13 May 2025 13:40:10 -0400 Subject: [PATCH] Report error from storeAccessToken() upstream. This will at least notify caller than the refresh token mechanism failed and should be tried again. May need to amend with more detailed error information from the underlying failure if needed, which would require a more detailed refactor. --- .../Shared/Handwritten/OAuth/OAuth.swift | 3 +++ .../Shared/Handwritten/OAuth/OAuthImpl.swift | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift index 30dc3ba5..f5c3a5e1 100644 --- a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift +++ b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift @@ -140,6 +140,9 @@ public enum OAuth2Error: String, Error { /// The state param received from the authorization server does not match the state param stored by the SDK. case inconsistentState = "inconsistent_state" + + /// Failed to save the token. + case tokenStorageError = "token_storage_error" /// Some other error (outside of the OAuth2 specification) case unknown diff --git a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift index b53aa732..cf4244c1 100644 --- a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift +++ b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift @@ -86,8 +86,11 @@ public class DropboxOAuthManager: AccessTokenRefreshing { } if canHandleURL(url) { extractFromUrl(url) { result in + var result = result if case let .success(token) = result { - self.storeAccessToken(token) + if !self.storeAccessToken(token) { + result = .error(.tokenStorageError, nil) + } } completion(result) } @@ -425,8 +428,12 @@ public class DropboxOAuthManager: AccessTokenRefreshing { uid: uid, refreshToken: refreshToken, scopes: scopes, appKey: appKey, locale: localeIdentifier ) refreshRequest.start(queue: DispatchQueue.main) { [weak self] result in + var result = result if case let .success(token) = result { - self?.storeAccessToken(token) + guard let self else { return } + if !self.storeAccessToken(token) { + result = .error(.tokenStorageError, nil) + } } (queue ?? DispatchQueue.main).async { completion(result) } }