Skip to content

Commit 2672ea1

Browse files
committed
fix remove session on error
1 parent 8eba9e2 commit 2672ea1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Sources/Auth/Internal/SessionManager.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,21 @@ private actor LiveSessionManager {
9797
eventEmitter.emit(.tokenRefreshed, session: session)
9898

9999
return session
100-
} catch let error as RetryableError {
101-
logger?.debug("Refresh token failed with a retryable error: \(error)")
102-
throw error
103100
} catch {
104-
logger?.debug("Refresh token failed with a non-retryable error: \(error)")
105-
106-
remove()
107-
108-
throw error
101+
logger?.debug("Refresh token failed with error: \(error)")
102+
103+
// DO NOT remove session in case it is an error that should be retried.
104+
// i.e. server instability, connection issues, ...
105+
//
106+
// Need to do this check here, because not all RetryableError's should be retried.
107+
// URLError conforms to RetryableError, but only a subset of URLError should be retried,
108+
// the same is true for AuthError.
109+
if let error = error as? any RetryableError, error.shouldRetry {
110+
throw error
111+
} else {
112+
remove()
113+
throw error
114+
}
109115
}
110116
}
111117

Sources/Helpers/RetryableError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
//
77
import Foundation
88

9+
/// An error type that can be retried.
910
package protocol RetryableError: Error {
11+
/// Whether this error instance should be retried or not.
1012
var shouldRetry: Bool { get }
1113
}
1214

0 commit comments

Comments
 (0)