Skip to content

Commit

Permalink
Merge pull request #805 from Infomaniak/fix-disconnect
Browse files Browse the repository at this point in the history
fix: Show login view on token loss
  • Loading branch information
valentinperignon authored Jun 14, 2023
2 parents cd825a2 + 4a741b2 commit 890bbb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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

0 comments on commit 890bbb8

Please sign in to comment.