Skip to content

Commit e799928

Browse files
author
Zach Jaquish
committed
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.
1 parent 24e57fa commit e799928

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public enum OAuth2Error: String, Error {
140140

141141
/// The state param received from the authorization server does not match the state param stored by the SDK.
142142
case inconsistentState = "inconsistent_state"
143+
144+
/// Failed to save the token.
145+
case tokenStorageError = "token_storage_error"
143146

144147
/// Some other error (outside of the OAuth2 specification)
145148
case unknown

Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ public class DropboxOAuthManager: AccessTokenRefreshing {
8686
}
8787
if canHandleURL(url) {
8888
extractFromUrl(url) { result in
89+
var result = result
8990
if case let .success(token) = result {
90-
self.storeAccessToken(token)
91+
if !self.storeAccessToken(token) {
92+
result = .error(.tokenStorageError, nil)
93+
}
9194
}
9295
completion(result)
9396
}
@@ -425,8 +428,12 @@ public class DropboxOAuthManager: AccessTokenRefreshing {
425428
uid: uid, refreshToken: refreshToken, scopes: scopes, appKey: appKey, locale: localeIdentifier
426429
)
427430
refreshRequest.start(queue: DispatchQueue.main) { [weak self] result in
431+
var result = result
428432
if case let .success(token) = result {
429-
self?.storeAccessToken(token)
433+
guard let self else { return }
434+
if !self.storeAccessToken(token) {
435+
result = .error(.tokenStorageError, nil)
436+
}
430437
}
431438
(queue ?? DispatchQueue.main).async { completion(result) }
432439
}

0 commit comments

Comments
 (0)