diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-05-11 12:25:46 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-05-11 19:12:40 +0200 |
| commit | f23b845c400dcbcba227f46630069d88ce3badb5 (patch) | |
| tree | 4133610db14d10d66507f1812f3c7f88d6d6487e | |
| parent | d174feb32ba4020244240e166e0bc0a4231245bb (diff) | |
| download | mullvadvpn-f23b845c400dcbcba227f46630069d88ce3badb5.tar.xz mullvadvpn-f23b845c400dcbcba227f46630069d88ce3badb5.zip | |
Localize SKError
Solves the problem with SKError returning "Operation cannot be completed" messages.
| -rw-r--r-- | ios/MullvadVPN/DisplayChainedError.swift | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/ios/MullvadVPN/DisplayChainedError.swift b/ios/MullvadVPN/DisplayChainedError.swift index daffe776b9..d7cfc5a81c 100644 --- a/ios/MullvadVPN/DisplayChainedError.swift +++ b/ios/MullvadVPN/DisplayChainedError.swift @@ -7,6 +7,7 @@ // import Foundation +import StoreKit protocol DisplayChainedError { var errorChainDescription: String? { get } @@ -113,7 +114,6 @@ extension TunnelManager.Error: DisplayChainedError { } extension Account.Error: DisplayChainedError { - var errorChainDescription: String? { switch self { case .createAccount(let restError), .verifyAccount(let restError): @@ -123,7 +123,25 @@ extension Account.Error: DisplayChainedError { return tunnelError.errorChainDescription } } +} +extension SKError: LocalizedError { + public var errorDescription: String? { + switch self.code { + case .unknown: + return NSLocalizedString("Unknown error", comment: "") + case .clientInvalid: + return NSLocalizedString("Client is not allowed to issue the request", comment: "") + case .paymentCancelled: + return NSLocalizedString("User cancelled the request", comment: "") + case .paymentInvalid: + return NSLocalizedString("Invalid purchase identifier", comment: "") + case .paymentNotAllowed: + return NSLocalizedString("This device is not allowed to make the payment", comment: "") + default: + return self.localizedDescription + } + } } extension AppStorePaymentManager.Error: DisplayChainedError { @@ -135,7 +153,9 @@ extension AppStorePaymentManager.Error: DisplayChainedError { case .readReceipt(let readReceiptError): switch readReceiptError { case .refresh(let storeError): - return String(format: NSLocalizedString("Cannot refresh the AppStore receipt: %@", comment: ""), storeError.localizedDescription) + let skErrorMessage = (storeError as? SKError)?.errorDescription ?? storeError.localizedDescription + + return String(format: NSLocalizedString("Cannot refresh the AppStore receipt: %@", comment: ""), skErrorMessage) case .io(let ioError): return String(format: NSLocalizedString("Cannot read the AppStore receipt from disk: %@", comment: ""), ioError.localizedDescription) case .doesNotExist: @@ -153,7 +173,7 @@ Please retry by using the "Restore purchases" button. return String(format: format, reason) case .storePayment(let storeError): - return storeError.localizedDescription + return (storeError as? SKError)?.errorDescription ?? storeError.localizedDescription } } } |
