summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/StorePaymentManager/StorePaymentManagerError.swift
blob: b64390a97d98f96b9a3bf429b8e014ee06a03065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
//  StorePaymentManagerError.swift
//  MullvadVPN
//
//  Created by pronebird on 08/09/2021.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadREST
import MullvadTypes

/// An error type emitted by `StorePaymentManager`.
enum StorePaymentManagerError: LocalizedError, WrappingError {
    /// Failure to find the account token associated with the transaction.
    case noAccountSet

    /// Failure to validate the account token.
    case validateAccount(Error)

    /// Failure to handle payment transaction. Contains error returned by StoreKit.
    case storePayment(Error)

    /// Failure to read the AppStore receipt.
    case readReceipt(Error)

    /// Failure to send the AppStore receipt to backend.
    case sendReceipt(Error)

    var errorDescription: String? {
        switch self {
        case .noAccountSet:
            return "Account is not set."
        case .validateAccount:
            return "Account validation error."
        case .storePayment:
            return "Store payment error."
        case .readReceipt:
            return "Read recept error."
        case .sendReceipt:
            return "Send receipt error."
        }
    }

    var underlyingError: Error? {
        switch self {
        case .noAccountSet:
            return nil
        case let .sendReceipt(error):
            return error
        case let .validateAccount(error):
            return error
        case let .readReceipt(error):
            return error
        case let .storePayment(error):
            return error
        }
    }
}