-
Notifications
You must be signed in to change notification settings - Fork 273
/
MASError.swift
104 lines (81 loc) · 2.56 KB
/
MASError.swift
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// MAError.swift
// mas-cli
//
// Created by Andrew Naylor on 21/08/2015.
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
//
import Foundation
public enum MASError: Error, Equatable {
case notSupported
case notSignedIn
case signInFailed(error: NSError?)
case alreadySignedIn
case purchaseFailed(error: NSError?)
case downloadFailed(error: NSError?)
case noDownloads
case cancelled
case searchFailed
case noSearchResultsFound
case noVendorWebsite
case notInstalled
case uninstallFailed
case urlEncoding
case noData
case jsonParsing(error: NSError?)
}
// MARK: - CustomStringConvertible
extension MASError: CustomStringConvertible {
public var description: String {
switch self {
case .notSignedIn:
return "Not signed in"
case .notSupported:
return """
This command is not supported on this macOS version due to changes in macOS. \
For more information see: \
https://github.com/mas-cli/mas#%EF%B8%8F-known-issues
"""
case .signInFailed(let error):
if let error = error {
return "Sign in failed: \(error.localizedDescription)"
} else {
return "Sign in failed"
}
case .alreadySignedIn:
return "Already signed in"
case .purchaseFailed(let error):
if let error = error {
return "Download request failed: \(error.localizedDescription)"
} else {
return "Download request failed"
}
case .downloadFailed(let error):
if let error = error {
return "Download failed: \(error.localizedDescription)"
} else {
return "Download failed"
}
case .noDownloads:
return "No downloads began"
case .cancelled:
return "Download cancelled"
case .searchFailed:
return "Search failed"
case .noSearchResultsFound:
return "No results found"
case .noVendorWebsite:
return "App does not have a vendor website"
case .notInstalled:
return "Not installed"
case .uninstallFailed:
return "Uninstall failed"
case .urlEncoding:
return "Unable to encode service URL"
case .noData:
return "Service did not return data"
case .jsonParsing:
return "Unable to parse response JSON"
}
}
}