-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIA-884: Add proper error handling for Login tvOS (#47)
* PIA-884: Add new class to handle errors instead of VM * PIA-884: Move Equatable extensions to tvOS target * PIA-884: Add proper error handling to login feature * PIA-884: Add missing files
- Loading branch information
1 parent
38d8906
commit 92a1d7a
Showing
17 changed files
with
635 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// LoginStatus.swift | ||
// PIA VPN-tvOS | ||
// | ||
// Created by Said Rehouni on 13/12/23. | ||
// Copyright © 2023 Private Internet Access Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum LoginCredentialsError { | ||
case none | ||
case username | ||
case password | ||
} | ||
|
||
enum LoginStatus { | ||
case none | ||
case isLogging | ||
case failed(errorMessage: String?, field: LoginCredentialsError) | ||
case succeeded(userAccount: UserAccount) | ||
} | ||
|
||
extension LoginStatus: Equatable { | ||
public static func == (lhs: LoginStatus, rhs: LoginStatus) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.none, .none), (.isLogging, .isLogging): | ||
return true | ||
case let (.failed(lhsErrorMessage, lhsField), .failed(rhsErrorMessage, rhsField)): | ||
return lhsErrorMessage == rhsErrorMessage && lhsField == rhsField | ||
case let (.succeeded(lhsAccount), .succeeded(rhsAccount)): | ||
return lhsAccount == rhsAccount | ||
default: | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
PIA VPN-tvOS/Login/Presentation/LoginViewModelErrorHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// LoginViewModelErrorHandler.swift | ||
// PIA VPN-tvOS | ||
// | ||
// Created by Said Rehouni on 13/12/23. | ||
// Copyright © 2023 Private Internet Access Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol LoginViewModelErrorHandlerType { | ||
func callAsFunction(error: LoginError) -> LoginStatus | ||
} | ||
|
||
class LoginViewModelErrorHandler: LoginViewModelErrorHandlerType { | ||
private let errorMapper: LoginPresentableErrorMapper | ||
|
||
init(errorMapper: LoginPresentableErrorMapper) { | ||
self.errorMapper = errorMapper | ||
} | ||
|
||
func callAsFunction(error: LoginError) -> LoginStatus { | ||
guard error != .usernameWrongFormat && error != .passwordWrongFormat else { | ||
return handleCredentialsError(error) | ||
} | ||
|
||
let message = errorMapper.map(error: error) | ||
return .failed(errorMessage: message, field: .none) | ||
} | ||
|
||
private func handleCredentialsError(_ error: LoginError) -> LoginStatus { | ||
let message = errorMapper.map(error: error) | ||
let field: LoginCredentialsError = error == .usernameWrongFormat ? .username : .password | ||
|
||
return .failed(errorMessage: message, field: field) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.