Skip to content

Commit

Permalink
1.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Jun 16, 2024
1 parent 5d8b9bb commit fd98252
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sources/SwiftAPIClient/Modifiers/HTTPResponseValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public extension HTTPResponseValidator {
/// - Parameter codes: The range of acceptable status codes.
/// - Returns: An `HTTPResponseValidator` that validates based on the specified status code range.
static func statusCode(_ codes: ClosedRange<Int>) -> Self {
HTTPResponseValidator { response, _, _ in
guard codes.contains(response.status.code) else {
HTTPResponseValidator { response, _, configs in
guard codes.contains(response.status.code) || configs.ignoreStatusCodeValidator else {
throw Errors.invalidStatusCode(response.status.code)
}
}
Expand All @@ -40,8 +40,8 @@ public extension HTTPResponseValidator {
/// - Parameter kind: The kind of acceptable status.
/// - Returns: An `HTTPResponseValidator` that validates based on the specified status kind.
static func statusCode(_ kind: HTTPResponse.Status.Kind) -> Self {
HTTPResponseValidator { response, _, _ in
guard response.status.kind == kind else {
HTTPResponseValidator { response, _, configs in
guard response.status.kind == kind || configs.ignoreStatusCodeValidator else {
throw Errors.invalidStatusCode(response.status.code)
}
}
Expand Down Expand Up @@ -82,3 +82,11 @@ public extension APIClient {
}
}
}

public extension APIClient.Configs {

var ignoreStatusCodeValidator: Bool {
get { self[\.ignoreStatusCodeValidator] ?? false }
set { self[\.ignoreStatusCodeValidator] = newValue }
}
}

0 comments on commit fd98252

Please sign in to comment.