-
-
Notifications
You must be signed in to change notification settings - Fork 202
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug report
Describe the bug
NSErrorthat areURLErrorare failing theRetryableErrorcoercion causing the session to be deleted when a token is refreshed offline
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Sign a user in
- Change date ahead to force a refresh
- Go offline
- Launch app
- Session is deleted
Reproducible in this playground as well:
/// An error type that can be retried.
protocol RetryableError: Error {
/// Whether this error instance should be retried or not.
var shouldRetry: Bool { get }
}
extension URLError: RetryableError {
var shouldRetry: Bool {
defaultRetryableURLErrorCodes.contains(code)
}
}
/// The default set of retryable URL error codes.
let defaultRetryableURLErrorCodes: Set<URLError.Code> = [
.backgroundSessionInUseByAnotherProcess, .backgroundSessionWasDisconnected,
.badServerResponse, .callIsActive, .cannotConnectToHost, .cannotFindHost,
.cannotLoadFromNetwork, .dataNotAllowed, .dnsLookupFailed,
.downloadDecodingFailedMidStream, .downloadDecodingFailedToComplete,
.internationalRoamingOff, .networkConnectionLost, .notConnectedToInternet,
.secureConnectionFailed, .serverCertificateHasBadDate,
.serverCertificateNotYetValid, .timedOut,
]
/// The default set of retryable HTTP status codes.
let defaultRetryableHTTPStatusCodes: Set<Int> = [
408, 500, 502, 503, 504,
]
let urlError = URLError(.notConnectedToInternet)
let userInfo: [String: Any] = [
NSLocalizedDescriptionKey: "The Internet connection appears to be offline.",
NSURLErrorFailingURLStringErrorKey: "https://awfgscmxufjzehndzbsx.supabase.co/auth/v1/token?grant_type=refresh_token",
NSURLErrorFailingURLErrorKey: "https://awfgscmxufjzehndzbsx.supabase.co/auth/v1/token?grant_type=refresh_token",
"_kCFStreamErrorCodeKey": 50,
"_NSURLErrorNWResolutionReportKey": "Resolved 0 endpoints in 1ms using unknown from cache",
"_NSURLErrorNWPathKey": "unsatisfied (No network route)",
"_kCFStreamErrorDomainKey": 1,
"_NSURLErrorFailingURLSessionTaskErrorKey": "LocalDataTask <FE281022-A8F4-4FB9-B8A2-20E8A3C98BEC>.<6>",
"_NSURLErrorRelatedURLSessionTaskErrorKey": [
"LocalDataTask <FE281022-A8F4-4FB9-B8A2-20E8A3C98BEC>.<6>"
]
]
let nsError = NSError(domain: NSURLErrorDomain, code: NSURLErrorNotConnectedToInternet, userInfo: userInfo)
print(urlError as? RetryableError) // Returns a RetryableError
print(nsError as? URLError as? RetryableError) // Returns a RetryableError
print(nsError as? RetryableError) // Returns nil
Expected behavior
- A users session should be maintained when offline and the token should be refreshed the next time available
System information
- OS: iOS
- Version of supabase-swift: 2.20.5
florianmari
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working