@@ -31,7 +31,8 @@ public class PostgrestBuilder {
31
31
/// - count: A `CountOption` determining how many items to return. Defaults to `nil`
32
32
/// - completion: Escaping completion handler with either a `PostgrestResponse` or an `Error`. Called after API call is completed and validated.
33
33
public func execute(
34
- head: Bool = false , count: CountOption ? = nil ,
34
+ head: Bool = false ,
35
+ count: CountOption ? = nil ,
35
36
completion: @escaping ( Result < PostgrestResponse , Error > ) -> Void
36
37
) {
37
38
let request : URLRequest
@@ -63,7 +64,7 @@ public class PostgrestBuilder {
63
64
64
65
do {
65
66
try Self . validate ( data: data, response: response)
66
- let response = try Self . parse ( data: data, response: response, request : request )
67
+ let response = PostgrestResponse ( data: data, response: response)
67
68
completion ( . success( response) )
68
69
} catch {
69
70
completion ( . failure( error) )
@@ -83,28 +84,7 @@ public class PostgrestBuilder {
83
84
return
84
85
}
85
86
86
- throw try JSONDecoder ( ) . decode ( PostgrestError . self, from: data)
87
- }
88
-
89
- /// Parses incoming data and server response into a `PostgrestResponse`
90
- /// - Parameters:
91
- /// - data: Data received from the server
92
- /// - response: Response received from the server
93
- /// - Throws: Throws an `Error` if invalid JSON.
94
- /// - Returns: Returns a `PostgrestResponse`
95
- private static func parse( data: Data , response: HTTPURLResponse , request: URLRequest ) throws
96
- -> PostgrestResponse
97
- {
98
- var count : Int ?
99
-
100
- if let contentRange = response. allHeaderFields [ " content-range " ] as? String ,
101
- let lastElement = contentRange. split ( separator: " / " ) . last
102
- {
103
- count = lastElement == " * " ? nil : Int ( lastElement)
104
- }
105
-
106
- let postgrestResponse = PostgrestResponse ( data: data, status: response. statusCode, count: count)
107
- return postgrestResponse
87
+ throw try JSONDecoder . postgrest. decode ( PostgrestError . self, from: data)
108
88
}
109
89
110
90
/// Builds the URL request for PostgREST
0 commit comments