Skip to content

Commit ef8ec3f

Browse files
committed
♻️ Removes throwing from validator.
Removes the throwing capability of validator to avoid confusion with the returned result.
1 parent 589a763 commit ef8ec3f

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

Sources/HTTPNetworking/Plugins/HTTPResponseValidator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public typealias ValidationResult = Result<Void, Error>
1111
/// By conforming to ``HTTPResponseValidator`` you can implement both simple and complex logic for validating
1212
/// the response of an ``HTTPRequest``. Common use cases include validating the status code or headers of a response.
1313
public protocol HTTPResponseValidator {
14-
func validate(_ response: HTTPURLResponse, for request: URLRequest, with data: Data) async throws -> ValidationResult
14+
func validate(_ response: HTTPURLResponse, for request: URLRequest, with data: Data) async -> ValidationResult
1515
}

Sources/HTTPNetworking/Plugins/Validators/Validator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public typealias ValidationHandler = (
44
_ response: HTTPURLResponse,
55
_ request: URLRequest,
66
_ data: Data
7-
) async throws -> ValidationResult
7+
) async -> ValidationResult
88

99
/// An ``HTTPResponseValidator`` that can be used to validate a response from an ``HTTPRequest``.
1010
public struct Validator: HTTPResponseValidator {
@@ -24,8 +24,8 @@ public struct Validator: HTTPResponseValidator {
2424

2525
// MARK: HTTPResponseValidator
2626

27-
public func validate(_ response: HTTPURLResponse, for request: URLRequest, with data: Data) async throws -> ValidationResult {
28-
try await handler(response, request, data)
27+
public func validate(_ response: HTTPURLResponse, for request: URLRequest, with data: Data) async -> ValidationResult {
28+
await handler(response, request, data)
2929
}
3030
}
3131

Sources/HTTPNetworking/Plugins/Validators/ZipValidator.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ public struct ZipValidator: HTTPResponseValidator {
2828

2929
// MARK: ResponseValidator
3030

31-
public func validate(_ response: HTTPURLResponse, for request: URLRequest, with data: Data) async throws -> ValidationResult {
31+
public func validate(_ response: HTTPURLResponse, for request: URLRequest, with data: Data) async -> ValidationResult {
3232
for validator in validators {
33-
try Task.checkCancellation()
33+
do { try Task.checkCancellation() }
34+
catch { return .failure(error) }
3435

35-
if case .failure(let error) = try await validator.validate(response, for: request, with: data) {
36+
if case .failure(let error) = await validator.validate(response, for: request, with: data) {
3637
return .failure(error)
3738
}
3839
}

Tests/HTTPNetworkingTests/HTTPRequestTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ class HTTPRequestTests: XCTestCase {
624624
]),
625625
validators: [
626626
Validator { _, _, _ in
627-
throw expectedError
627+
.failure(expectedError)
628628
}
629629
]
630630
)
@@ -652,7 +652,7 @@ class HTTPRequestTests: XCTestCase {
652652
_ = try await client
653653
.request(for: .get, to: url, expecting: [String].self)
654654
.validate { _, _, _ in
655-
throw expectedError
655+
.failure(expectedError)
656656
}
657657
.run()
658658
} catch {

0 commit comments

Comments
 (0)