|
7 | 7 | import Foundation
|
8 | 8 | import ReadiumShared
|
9 | 9 |
|
10 |
| -public enum LCPError: LocalizedError { |
| 10 | +public enum LCPError: Error { |
11 | 11 | /// The license could not be retrieved because the passphrase is unknown.
|
12 | 12 | case missingPassphrase
|
13 | 13 |
|
@@ -52,138 +52,51 @@ public enum LCPError: LocalizedError {
|
52 | 52 |
|
53 | 53 | /// An unknown low-level error was reported.
|
54 | 54 | case unknown(Error?)
|
55 |
| - |
56 |
| - public var errorDescription: String? { |
57 |
| - switch self { |
58 |
| - case .missingPassphrase: return nil |
59 |
| - case .notALicenseDocument: return nil |
60 |
| - case .licenseIsBusy: |
61 |
| - return ReadiumLCPLocalizedString("LCPError.licenseIsBusy") |
62 |
| - case let .licenseIntegrity(error): |
63 |
| - let description: String = { |
64 |
| - switch error { |
65 |
| - case .licenseOutOfDate: |
66 |
| - return ReadiumLCPLocalizedString("LCPClientError.licenseOutOfDate") |
67 |
| - case .certificateRevoked: |
68 |
| - return ReadiumLCPLocalizedString("LCPClientError.certificateRevoked") |
69 |
| - case .certificateSignatureInvalid: |
70 |
| - return ReadiumLCPLocalizedString("LCPClientError.certificateSignatureInvalid") |
71 |
| - case .licenseSignatureDateInvalid: |
72 |
| - return ReadiumLCPLocalizedString("LCPClientError.licenseSignatureDateInvalid") |
73 |
| - case .licenseSignatureInvalid: |
74 |
| - return ReadiumLCPLocalizedString("LCPClientError.licenseSignatureInvalid") |
75 |
| - case .contextInvalid: |
76 |
| - return ReadiumLCPLocalizedString("LCPClientError.contextInvalid") |
77 |
| - case .contentKeyDecryptError: |
78 |
| - return ReadiumLCPLocalizedString("LCPClientError.contentKeyDecryptError") |
79 |
| - case .userKeyCheckInvalid: |
80 |
| - return ReadiumLCPLocalizedString("LCPClientError.userKeyCheckInvalid") |
81 |
| - case .contentDecryptError: |
82 |
| - return ReadiumLCPLocalizedString("LCPClientError.contentDecryptError") |
83 |
| - case .unknown: |
84 |
| - return ReadiumLCPLocalizedString("LCPClientError.unknown") |
85 |
| - } |
86 |
| - }() |
87 |
| - return ReadiumLCPLocalizedString("LCPError.licenseIntegrity", description) |
88 |
| - case let .licenseStatus(error): |
89 |
| - return error.localizedDescription |
90 |
| - case .licenseContainer: |
91 |
| - return ReadiumLCPLocalizedString("LCPError.licenseContainer") |
92 |
| - case .licenseInteractionNotAvailable: |
93 |
| - return ReadiumLCPLocalizedString("LCPError.licenseInteractionNotAvailable") |
94 |
| - case .licenseProfileNotSupported: |
95 |
| - return ReadiumLCPLocalizedString("LCPError.licenseProfileNotSupported") |
96 |
| - case .crlFetching: |
97 |
| - return ReadiumLCPLocalizedString("LCPError.crlFetching") |
98 |
| - case let .licenseRenew(error): |
99 |
| - return error.localizedDescription |
100 |
| - case let .licenseReturn(error): |
101 |
| - return error.localizedDescription |
102 |
| - case .parsing: |
103 |
| - return ReadiumLCPLocalizedString("LCPError.parsing") |
104 |
| - case let .network(error): |
105 |
| - return error?.localizedDescription ?? ReadiumLCPLocalizedString("LCPError.network") |
106 |
| - case let .runtime(error): |
107 |
| - return error |
108 |
| - case let .unknown(error): |
109 |
| - return error?.localizedDescription |
110 |
| - } |
111 |
| - } |
112 | 55 | }
|
113 | 56 |
|
114 | 57 | /// Errors while checking the status of the License, using the Status Document.
|
115 |
| -public enum StatusError: LocalizedError { |
116 |
| - // For the case (revoked, returned, cancelled, expired), app should notify the user and stop there. The message to the user must be clear about the status of the license: don't display "expired" if the status is "revoked". The date and time corresponding to the new status should be displayed (e.g. "The license expired on 01 January 2018"). |
| 58 | +/// |
| 59 | +/// For the case (revoked, returned, cancelled, expired), app should notify the |
| 60 | +/// user and stop there. The message to the user must be clear about the status |
| 61 | +/// of the license: don't display "expired" if the status is "revoked". The |
| 62 | +/// date and time corresponding to the new status should be displayed (e.g. |
| 63 | +/// "The license expired on 01 January 2018"). |
| 64 | +/// |
| 65 | +/// If the license has been revoked, the user message should display the number |
| 66 | +/// of devices which registered to the server. This count can be calculated |
| 67 | +/// from the number of "register" events in the status document. If no event is |
| 68 | +/// logged in the status document, no such message should appear (certainly not |
| 69 | +/// "The license was registered by 0 devices"). |
| 70 | +public enum StatusError: Error { |
| 71 | + /// This license was cancelled on the given date. |
117 | 72 | case cancelled(Date)
|
| 73 | + /// This license has been returned on the given date. |
118 | 74 | case returned(Date)
|
| 75 | + /// This license started and expired on the given dates. |
119 | 76 | case expired(start: Date, end: Date)
|
120 |
| - // If the license has been revoked, the user message should display the number of devices which registered to the server. This count can be calculated from the number of "register" events in the status document. If no event is logged in the status document, no such message should appear (certainly not "The license was registered by 0 devices"). |
| 77 | + /// This license was revoked on the given date, after being activated on |
| 78 | + /// `devicesCount` devices. |
121 | 79 | case revoked(Date, devicesCount: Int)
|
122 |
| - |
123 |
| - public var errorDescription: String? { |
124 |
| - let dateFormatter = DateFormatter() |
125 |
| - dateFormatter.dateStyle = .medium |
126 |
| - |
127 |
| - switch self { |
128 |
| - case let .cancelled(date): |
129 |
| - return ReadiumLCPLocalizedString("StatusError.cancelled", dateFormatter.string(from: date)) |
130 |
| - |
131 |
| - case let .returned(date): |
132 |
| - return ReadiumLCPLocalizedString("StatusError.returned", dateFormatter.string(from: date)) |
133 |
| - |
134 |
| - case let .expired(start: start, end: end): |
135 |
| - if start > Date() { |
136 |
| - return ReadiumLCPLocalizedString("StatusError.expired.start", dateFormatter.string(from: start)) |
137 |
| - } else { |
138 |
| - return ReadiumLCPLocalizedString("StatusError.expired.end", dateFormatter.string(from: end)) |
139 |
| - } |
140 |
| - |
141 |
| - case let .revoked(date, devicesCount): |
142 |
| - return ReadiumLCPLocalizedString("StatusError.revoked", dateFormatter.string(from: date), devicesCount) |
143 |
| - } |
144 |
| - } |
145 | 80 | }
|
146 | 81 |
|
147 | 82 | /// Errors while renewing a loan.
|
148 |
| -public enum RenewError: LocalizedError { |
| 83 | +public enum RenewError: Error { |
149 | 84 | // Your publication could not be renewed properly.
|
150 | 85 | case renewFailed
|
151 | 86 | // Incorrect renewal period, your publication could not be renewed.
|
152 | 87 | case invalidRenewalPeriod(maxRenewDate: Date?)
|
153 | 88 | // An unexpected error has occurred on the licensing server.
|
154 | 89 | case unexpectedServerError
|
155 |
| - |
156 |
| - public var errorDescription: String? { |
157 |
| - switch self { |
158 |
| - case .renewFailed: |
159 |
| - return ReadiumLCPLocalizedString("RenewError.renewFailed") |
160 |
| - case .invalidRenewalPeriod(maxRenewDate: _): |
161 |
| - return ReadiumLCPLocalizedString("RenewError.invalidRenewalPeriod") |
162 |
| - case .unexpectedServerError: |
163 |
| - return ReadiumLCPLocalizedString("RenewError.unexpectedServerError") |
164 |
| - } |
165 |
| - } |
166 | 90 | }
|
167 | 91 |
|
168 | 92 | /// Errors while returning a loan.
|
169 |
| -public enum ReturnError: LocalizedError { |
| 93 | +public enum ReturnError: Error { |
170 | 94 | // Your publication could not be returned properly.
|
171 | 95 | case returnFailed
|
172 | 96 | // Your publication has already been returned before or is expired.
|
173 | 97 | case alreadyReturnedOrExpired
|
174 | 98 | // An unexpected error has occurred on the licensing server.
|
175 | 99 | case unexpectedServerError
|
176 |
| - |
177 |
| - public var errorDescription: String? { |
178 |
| - switch self { |
179 |
| - case .returnFailed: |
180 |
| - return ReadiumLCPLocalizedString("ReturnError.returnFailed") |
181 |
| - case .alreadyReturnedOrExpired: |
182 |
| - return ReadiumLCPLocalizedString("ReturnError.alreadyReturnedOrExpired") |
183 |
| - case .unexpectedServerError: |
184 |
| - return ReadiumLCPLocalizedString("ReturnError.unexpectedServerError") |
185 |
| - } |
186 |
| - } |
187 | 100 | }
|
188 | 101 |
|
189 | 102 | /// Errors while parsing the License or Status JSON Documents.
|
|
0 commit comments