Revalidate the API keys if they are expired. Fixes #3210
This commit is contained in:
parent
05e3ff9fd2
commit
8828c0eaaa
|
@ -136,10 +136,37 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
|||
case .failure(let error):
|
||||
DispatchQueue.main.async {
|
||||
self.refreshProgress.clear()
|
||||
|
||||
let wrappedError = AccountError.wrappedError(error: error, account: account)
|
||||
if wrappedError.isCredentialsError, let basicCredentials = try? account.retrieveCredentials(type: .readerBasic), let endpoint = account.endpointURL {
|
||||
self.caller.credentials = basicCredentials
|
||||
|
||||
self.caller.validateCredentials(endpoint: endpoint) { result in
|
||||
switch result {
|
||||
case .success(let apiCredentials):
|
||||
if let apiCredentials = apiCredentials {
|
||||
DispatchQueue.main.async {
|
||||
try? account.storeCredentials(apiCredentials)
|
||||
self.caller.credentials = apiCredentials
|
||||
self.refreshAll(for: account, completion: completion)
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(wrappedError))
|
||||
}
|
||||
}
|
||||
case .failure:
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(wrappedError))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
completion(.failure(wrappedError))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue