Skip to content

Commit

Permalink
Apply failWhenAnyNestedRequestErrors property to the collection reque…
Browse files Browse the repository at this point in the history
…st (#20)

* Apply failWhenAnyNestedRequestErrors property to the collection request
* Update podspec
  • Loading branch information
z-turk3 authored Jun 19, 2024
1 parent 4b4bea6 commit ddfc83b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
18 changes: 4 additions & 14 deletions Examples/CocoaPods/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Halley.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Halley'
s.version = '1.8.0'
s.version = '1.8.1'
s.summary = 'Lightweight JSON HAL parser and traverser.'
s.description = <<-DESC
Halley provides a simple way on iOS to parse and traverse models according to JSON Hypertext Application Language specification also known just as HAL.
Expand Down
6 changes: 3 additions & 3 deletions Halley/Core/Traverser/Traverser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private extension Traverser {
)
}
.zip()
.map { $0.collect() }
.map { $0.collect(options: options) }
.eraseToAnyPublisher()
}

Expand Down Expand Up @@ -390,7 +390,7 @@ private extension Traverser {

return requests
.zip()
.map { $0.collect() }
.map { $0.collect(options: options) }
.eraseToAnyPublisher()
}
}
Expand Down Expand Up @@ -576,7 +576,7 @@ private extension Traverser {
}
return singleResourceRequests
.zip()
.map { $0.map(\.result).collect() }
.map { $0.map(\.result).collect(options: options) }
.map { Relationship.Response(relationship: relOptions.relationship, result: $0) }
.eraseToAnyPublisher()
case (.toOne, .array(let links)):
Expand Down
14 changes: 9 additions & 5 deletions Halley/Core/Utils/Result+Transform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ extension JSONResult {

extension Collection where Element == JSONResult {

/// Collects all responses and joins them as a single array. In case if any
/// of responses has error, it will return .failure
/// - Returns: `.success` if all responses are successful, `.failure` if any of responses have failed
func collect() -> JSONResult {
/// Collects all responses and joins them as a single array. Depending on the `options` property
/// `failWhenAnyNestedRequestErrors`, method will return a success or failure.
///
/// - Returns: `.success` if all responses are successful, `.failure` if any response
/// has failed and the `failWhenAnyNestedRequestErrors` property is set to `true`
func collect(options: HalleyKit.Options) -> JSONResult {
do {
let joined = try map { try $0.get() }
let joined = try compactMap {
options.failWhenAnyNestedRequestErrors ? try $0.get() : try? $0.get()
}
return .success(joined)
} catch let error {
return .failure(error)
Expand Down

0 comments on commit ddfc83b

Please sign in to comment.