Skip to content

Commit

Permalink
1.7.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Apr 12, 2024
1 parent a71632d commit c5898e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.7.8")
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.7.9")
],
targets: [
.target(
Expand Down
22 changes: 13 additions & 9 deletions Sources/SwiftAPIClient/APIClientCaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ public extension APIClient {
return try serializer.serialize(response, configs)
} catch {
if let data = response as? Data, let failure = configs.errorDecoder.decodeError(data, configs) {
configs.errorHandler(failure, configs)
try configs.errorHandler(failure, configs)
throw failure
}
configs.errorHandler(error, configs)
try configs.errorHandler(error, configs)
throw error
}
}
}
} catch {
withConfigs { configs in
try withConfigs { configs in
let fileIDLine = configs.fileIDLine ?? FileIDLine(fileID: fileID, line: line)
if !configs.loggingComponents.isEmpty {
let message = configs.loggingComponents.errorMessage(
Expand All @@ -217,7 +217,7 @@ public extension APIClient {
)
configs.logger.error("\(message)")
}
configs.errorHandler(error, configs)
try configs.errorHandler(error, configs)
}
throw error
}
Expand All @@ -226,7 +226,7 @@ public extension APIClient {

public extension APIClient.Configs {

var errorHandler: (Error, APIClient.Configs) -> Void {
var errorHandler: (Error, APIClient.Configs) throws -> Void {
get { self[\.errorHandler] ?? { _, _ in } }
set { self[\.errorHandler] = newValue }
}
Expand All @@ -235,12 +235,16 @@ public extension APIClient.Configs {
public extension APIClient {

/// Sets the error handler.
func errorHandler(_ handler: @escaping (Error, APIClient.Configs) -> Void) -> APIClient {
func errorHandler(_ handler: @escaping (Error, APIClient.Configs) throws -> Void) -> APIClient {
configs { configs in
let current = configs.errorHandler
configs.errorHandler = { error, configs in
current(error, configs)
handler(error, configs)
configs.errorHandler = { failure, configs in
do {
try current(failure, configs)
} catch {
try handler(error, configs)
throw error
}
}
}
}
Expand Down

0 comments on commit c5898e3

Please sign in to comment.