File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Sources/async-http-client/validate/type Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ public extension Http.Validate{
1515
1616 public typealias Predicate = ( Int ) -> Bool
1717
18+ public typealias ErrorFn = ( Int , Data ? ) -> Error ?
19+
1820 /// Validate by exact value
1921 case const( Int = 200 )
2022
@@ -23,6 +25,9 @@ public extension Http.Validate{
2325
2426 /// Validate by predicate func if you need some specific logic
2527 case predicate( Predicate )
28+
29+ /// Check status and emit error if status is not valid
30+ case check( ErrorFn )
2631 }
2732}
2833
@@ -54,6 +59,10 @@ public extension Http.Validate.Status{
5459 if !value. contains ( status) { try err ( status, response, with: data) }
5560 case . predicate( let fn) :
5661 if !fn( status) { try err ( status, response, with: data) }
62+ case . check( let checkFn) :
63+ if let error = checkFn ( status, data) {
64+ throw error
65+ }
5766 }
5867 }
5968}
You can’t perform that action at this time.
0 commit comments