Skip to content

Commit 1796b20

Browse files
committed
Make DotComError data available for all cases
1 parent ffd81e1 commit 1796b20

File tree

35 files changed

+79
-76
lines changed

35 files changed

+79
-76
lines changed

Modules/Sources/Fakes/NetworkingCore.generated.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension NetworkingCore.DotcomError {
4444
/// Returns a "ready to use" type filled with fake values.
4545
///
4646
public static func fake() -> NetworkingCore.DotcomError {
47-
.empty
47+
.empty()
4848
}
4949
}
5050
extension NetworkingCore.MetaContainer {

Modules/Sources/Networking/Remote/DevicesRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class DevicesRemote: Remote {
5656

5757
enqueue(request, mapper: mapper) { (success, error) in
5858
guard success == true else {
59-
completion(error ?? DotcomError.empty)
59+
completion(error ?? DotcomError.empty())
6060
return
6161
}
6262

Modules/Sources/NetworkingCore/Model/DotcomError.swift

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ public enum DotcomError: Error, Decodable, Equatable, GeneratedFakeable {
77

88
/// Non explicit reason
99
///
10-
case empty
10+
case empty(data: [String: AnyDecodable]? = nil)
1111

1212
/// Missing Token!
1313
///
14-
case unauthorized
14+
case unauthorized(data: [String: AnyDecodable]? = nil)
1515

1616
/// We're not properly authenticated
1717
///
18-
case invalidToken
18+
case invalidToken(data: [String: AnyDecodable]? = nil)
1919

2020
/// Remote Request Failed
2121
///
22-
case requestFailed
22+
case requestFailed(data: [String: AnyDecodable]? = nil)
2323

2424
/// No route was found matching the URL and request method
2525
///
26-
case noRestRoute
26+
case noRestRoute(data: [String: AnyDecodable]? = nil)
2727

2828
/// Jetpack is not connected
2929
///
3030
/// This can be caused by an `unknown_token` error from Jetpack
3131
/// or an `invalid_blog` error from WordPress.com Stats.
3232
///
33-
case jetpackNotConnected
33+
case jetpackNotConnected(data: [String: AnyDecodable]? = nil)
3434

3535
/// Unknown: Represents an unmapped remote error. Capisce?
3636
///
@@ -41,13 +41,13 @@ public enum DotcomError: Error, Decodable, Equatable, GeneratedFakeable {
4141
/// Note: when the cases get large, consider refactoring them into a separate error enum that conforms to a Dotcom error protocol
4242

4343
/// No permission to view site stats
44-
case noStatsPermission
44+
case noStatsPermission(data: [String: AnyDecodable]? = nil)
4545

4646
/// Jetpack site stats module disabled
47-
case statsModuleDisabled
47+
case statsModuleDisabled(data: [String: AnyDecodable]? = nil)
4848

4949
/// The requested resourced does not exist remotely
50-
case resourceDoesNotExist
50+
case resourceDoesNotExist(data: [String: AnyDecodable]? = nil)
5151

5252
/// Decodable Initializer.
5353
///
@@ -59,22 +59,22 @@ public enum DotcomError: Error, Decodable, Equatable, GeneratedFakeable {
5959

6060
switch error {
6161
case Constants.invalidToken:
62-
self = .invalidToken
62+
self = .invalidToken(data: data)
6363
case Constants.requestFailed:
64-
self = .requestFailed
64+
self = .requestFailed(data: data)
6565
case Constants.unauthorized where message == ErrorMessages.noStatsPermission:
66-
self = .noStatsPermission
66+
self = .noStatsPermission(data: data)
6767
case Constants.unauthorized:
68-
self = .unauthorized
68+
self = .unauthorized(data: data)
6969
case Constants.noRestRoute:
70-
self = .noRestRoute
70+
self = .noRestRoute(data: data)
7171
case Constants.invalidBlog where message == ErrorMessages.statsModuleDisabled:
72-
self = .statsModuleDisabled
72+
self = .statsModuleDisabled(data: data)
7373
case Constants.restTermInvalid where message == ErrorMessages.resourceDoesNotExist:
74-
self = .resourceDoesNotExist
74+
self = .resourceDoesNotExist(data: data)
7575
case Constants.unknownToken,
7676
Constants.invalidBlog where message == ErrorMessages.jetpackNotConnected:
77-
self = .jetpackNotConnected
77+
self = .jetpackNotConnected(data: data)
7878
default:
7979
self = .unknown(code: error, message: message, data: data)
8080
}
@@ -151,12 +151,15 @@ extension DotcomError: CustomStringConvertible {
151151
//
152152
public func ==(lhs: DotcomError, rhs: DotcomError) -> Bool {
153153
switch (lhs, rhs) {
154-
case (.requestFailed, .requestFailed),
154+
case (.empty, .empty),
155155
(.unauthorized, .unauthorized),
156+
(.invalidToken, .invalidToken),
157+
(.requestFailed, .requestFailed),
156158
(.noRestRoute, .noRestRoute),
159+
(.jetpackNotConnected, .jetpackNotConnected),
157160
(.noStatsPermission, .noStatsPermission),
158161
(.statsModuleDisabled, .statsModuleDisabled),
159-
(.jetpackNotConnected, .jetpackNotConnected):
162+
(.resourceDoesNotExist, .resourceDoesNotExist):
160163
return true
161164
case let (.unknown(codeLHS, _, _), .unknown(codeRHS, _, _)):
162165
return codeLHS == codeRHS

Modules/Sources/NetworkingCore/Remote/NotificationsRemote.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class NotificationsRemote: Remote, NotificationsRemoteProtocol {
7474

7575
enqueue(request, mapper: mapper) { (success, error) in
7676
guard success == true else {
77-
completion(error ?? DotcomError.empty)
77+
completion(error ?? DotcomError.empty())
7878
return
7979
}
8080

@@ -99,7 +99,7 @@ public final class NotificationsRemote: Remote, NotificationsRemoteProtocol {
9999

100100
enqueue(request, mapper: mapper) { (success, error) in
101101
guard success == true else {
102-
completion(error ?? DotcomError.empty)
102+
completion(error ?? DotcomError.empty())
103103
return
104104
}
105105

Modules/Sources/Yosemite/Stores/ProductStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ private extension ProductStore {
685685
feature: .productDetailsFromScannedTexts,
686686
responseFormat: .json)
687687
guard let jsonData = jsonString.data(using: .utf8) else {
688-
return completion(.failure(DotcomError.resourceDoesNotExist))
688+
return completion(.failure(DotcomError.resourceDoesNotExist()))
689689
}
690690
let details = try JSONDecoder().decode(ProductDetailsFromScannedTexts.self, from: jsonData)
691691
completion(.success(.init(name: details.name, description: details.description)))

Modules/Sources/Yosemite/Stores/ShippingLabelStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private extension ShippingLabelStore {
161161
}
162162
onCompletion(eligibility.isEligible)
163163
case .failure(let error):
164-
if error as? DotcomError == .noRestRoute {
164+
if case .noRestRoute = error as? DotcomError {
165165
DDLogError("⚠️ Endpoint for shipping label creation eligibility is unreachable for order: \(orderID). WC Shipping plugin may be missing.")
166166
} else {
167167
DDLogError("⛔️ Error checking shipping label creation eligibility for order \(orderID): \(error)")

Modules/Sources/Yosemite/Stores/WooShippingStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private extension WooShippingStore {
120120
}
121121
onCompletion(eligibility.isEligible)
122122
case .failure(let error):
123-
if error as? DotcomError == .noRestRoute {
123+
if case .noRestRoute = error as? DotcomError {
124124
DDLogError("⚠️ Endpoint for shipping label creation eligibility is unreachable for order: \(orderID). WC Shipping plugin may be missing.")
125125
} else {
126126
DDLogError("⛔️ Error checking shipping label creation eligibility for order \(orderID): \(error)")

Modules/Tests/NetworkingTests/Remote/CommentRemoteTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class CommentRemoteTests: XCTestCase {
147147
return
148148
}
149149

150-
XCTAssert(error == .unauthorized)
150+
XCTAssert(error == .unauthorized())
151151
XCTAssertNil(updatedStatus)
152152

153153
expectation.fulfill()

Modules/Tests/NetworkingTests/Remote/NotificationsRemoteTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ final class NotificationsRemoteTests: XCTestCase {
9595
return
9696
}
9797

98-
XCTAssert(error == .unauthorized)
98+
XCTAssert(error == .unauthorized())
9999
expectation.fulfill()
100100
}
101101

@@ -132,7 +132,7 @@ final class NotificationsRemoteTests: XCTestCase {
132132
return
133133
}
134134

135-
XCTAssert(error == .unauthorized)
135+
XCTAssert(error == .unauthorized())
136136

137137
expectation.fulfill()
138138
}

Modules/Tests/NetworkingTests/Remote/ProductsReportsRemoteTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ class ProductsReportsRemoteTests: XCTestCase {
5656
earliestDateToInclude: Date(),
5757
latestDateToInclude: Date(),
5858
quantity: 5)
59-
}, errorAssert: { ($0 as? DotcomError) == .unauthorized })
59+
}, errorAssert: { ($0 as? DotcomError) == .unauthorized() })
6060
}
6161
}

0 commit comments

Comments
 (0)