Skip to content

Commit

Permalink
1.7.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Apr 12, 2024
1 parent 6452e3d commit a71632d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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.7")
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.7.8")
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ 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)
throw failure
}
configs.errorHandler(error, configs)
throw error
}
}
Expand All @@ -215,8 +217,31 @@ public extension APIClient {
)
configs.logger.error("\(message)")
}
configs.errorHandler(error, configs)
}
throw error
}
}
}

public extension APIClient.Configs {

var errorHandler: (Error, APIClient.Configs) -> Void {
get { self[\.errorHandler] ?? { _, _ in } }
set { self[\.errorHandler] = newValue }
}
}

public extension APIClient {

/// Sets the error handler.
func errorHandler(_ handler: @escaping (Error, APIClient.Configs) -> Void) -> APIClient {
configs { configs in
let current = configs.errorHandler
configs.errorHandler = { error, configs in
current(error, configs)
handler(error, configs)
}
}
}
}

0 comments on commit a71632d

Please sign in to comment.