Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show login view on token loss #805

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Mail/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDelegate
// `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
accountManager = AccountManager.instance
accountManager.delegate = self
updateWindowUI()
setupLaunch()
if let mailToURL = connectionOptions.urlContexts.first?.url {
Expand Down Expand Up @@ -107,7 +108,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDelegate
}

func currentAccountNeedsAuthentication() {
showLoginView()
DispatchQueue.main.async { [weak self] in
self?.showLoginView()
}
}

private func setupLaunch() {
Expand Down
17 changes: 12 additions & 5 deletions MailCore/API/MailApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,27 @@ public extension ApiFetcher {
public class MailApiFetcher: ApiFetcher {
public static let clientId = "E90BC22D-67A8-452C-BE93-28DA33588CA4"

/// All status except 401 are handled by our code, 401 status is handled by Alamofire's Authenticator code
private lazy var handledHttpStatus: Set<Int> = {
var allStatus = Set(200 ... 500)
allStatus.remove(401)
return allStatus
}()

override public func perform<T: Decodable>(
request: DataRequest,
decoder: JSONDecoder = ApiFetcher.decoder
) async throws -> (data: T, responseAt: Int?) {
do {
return try await super.perform(request: request)
} catch let InfomaniakError.apiError(apiError) {
return try await super.perform(request: request.validate(statusCode: handledHttpStatus))
} catch InfomaniakError.apiError(let apiError) {
throw MailApiError.mailApiErrorWithFallback(apiErrorCode: apiError.code)
} catch let InfomaniakError.serverError(statusCode: statusCode) {
} catch InfomaniakError.serverError(statusCode: let statusCode) {
throw MailServerError(httpStatus: statusCode)
} catch {
if let afError = error.asAFError {
if case let .responseSerializationFailed(reason) = afError,
case let .decodingFailed(error) = reason {
if case .responseSerializationFailed(let reason) = afError,
case .decodingFailed(let error) = reason {
var rawJson = "No data"
if let data = request.data,
let stringData = String(data: data, encoding: .utf8) {
Expand Down