Skip to content

Commit 4e17cf1

Browse files
[BWA-155] Move ResponseValidationHandler to BitwardenKit (#1486)
1 parent 93a98c7 commit 4e17cf1

File tree

25 files changed

+99
-187
lines changed

25 files changed

+99
-187
lines changed

AuthenticatorShared/Core/Platform/Extentions/Error+Networking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import Foundation
23

34
public extension Error {

AuthenticatorShared/Core/Platform/Extentions/ErrorNetworkingTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import BitwardenKit
2+
import BitwardenKitMocks
23
import Networking
34
import TestHelpers
45
import XCTest

AuthenticatorShared/Core/Platform/Services/API/Errors/ServerError.swift

Lines changed: 0 additions & 29 deletions
This file was deleted.

AuthenticatorShared/Core/Platform/Services/API/Handlers/ResponseValidationHandlerTests.swift

Lines changed: 0 additions & 57 deletions
This file was deleted.

AuthenticatorShared/UI/Platform/Application/Extensions/Alert+Networking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import BitwardenSdk
23
import Foundation
34

AuthenticatorShared/UI/Platform/Application/Extensions/Alert+NetworkingTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// swiftlint:disable:this file_name
22

33
import BitwardenKit
4+
import BitwardenKitMocks
45
import Foundation
56
import Networking
67
import TestHelpers
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Foundation
2+
import Networking
3+
4+
// MARK: - ResponseValidationErrorModel
5+
6+
/// An Response validation error returned from an API request.
7+
///
8+
public struct ResponseValidationErrorModel: Codable, Equatable {
9+
// MARK: Properties
10+
11+
/// A string that represents the error code.
12+
public let error: String
13+
14+
/// A string that provides a description of the error.
15+
public let errorDescription: String?
16+
17+
/// An `ErrorModel` object that provides more details about the error.
18+
public let errorModel: ErrorModel
19+
20+
/// Public instance of synthesized initializer.
21+
public init(error: String, errorDescription: String?, errorModel: ErrorModel) {
22+
self.error = error
23+
self.errorDescription = errorDescription
24+
self.errorModel = errorModel
25+
}
26+
}
27+
28+
public struct ErrorModel: Codable, Equatable {
29+
// MARK: Properties
30+
31+
/// A string that provides a message about the error.
32+
public let message: String
33+
34+
/// A string that represents an object associated with the error.
35+
public let object: String
36+
37+
/// Public instance of synthesized initializer.
38+
public init(message: String, object: String) {
39+
self.message = message
40+
self.object = object
41+
}
42+
}
43+
44+
// MARK: JSONResponse
45+
46+
extension ResponseValidationErrorModel: JSONResponse {
47+
public static let decoder = JSONDecoder.pascalOrSnakeCaseDecoder
48+
}

BitwardenShared/Core/Auth/Models/Response/ResponseValidationErrorModelTests.swift renamed to BitwardenKit/Core/Auth/Models/Response/ResponseValidationErrorModelTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import BitwardenKitMocks
12
import TestHelpers
23
import XCTest
34

4-
@testable import BitwardenShared
5+
@testable import BitwardenKit
56

67
// MARK: - ResponseValidationErrorModelTests
78

BitwardenKit/Core/Auth/Services/API/Account/Fixtures/APITestData+Account.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,3 @@ public extension APITestData {
137137
bundle: BitwardenKitMocksBundleFinder.bundle
138138
)
139139
}
140-
141-
class BitwardenKitMocksBundleFinder {
142-
static let bundle = Bundle(for: BitwardenKitMocksBundleFinder.self)
143-
}

BitwardenShared/Core/Platform/Services/API/Errors/ServerError.swift renamed to BitwardenKit/Core/Platform/Services/API/Errors/ServerError.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import BitwardenKit
21
import Foundation
32

43
// MARK: - ServerError
54

65
/// An enumeration of server errors.
76
///
8-
enum ServerError: Error, Equatable, CustomNSError {
7+
public enum ServerError: Error, Equatable, CustomNSError {
98
/// A generic error.
109
///
1110
/// - Parameter errorResponse: The error response returned from the API request.
@@ -19,7 +18,7 @@ enum ServerError: Error, Equatable, CustomNSError {
1918
case validationError(validationErrorResponse: ResponseValidationErrorModel)
2019

2120
/// A computed property that returns an error message based on the case.
22-
var message: String {
21+
public var message: String {
2322
switch self {
2423
case let .error(errorResponse):
2524
errorResponse.singleMessage()

0 commit comments

Comments
 (0)