@@ -14,7 +14,7 @@ import retry_policy_service
1414public struct ReplicateAPI {
1515
1616 /// Client type alias
17- public typealias ReplicateClient = Http . Proxy < ReplicateAPI . JsonReader , JsonWriter >
17+ public typealias ReplicateClient = Http . Proxy < JsonReader , JsonWriter >
1818
1919 /// Communication layer
2020 private let client : ReplicateClient
@@ -75,10 +75,13 @@ public struct ReplicateAPI{
7575 public func getCollections( collection_slug : String ) async throws -> CollectionOfModels {
7676
7777 let path = " collections/ \( collection_slug) "
78- let rule = [ Http . Validate. status ( . range( 200 ..< 500 ) ) ]
79- let result : Http . Response < CollectionOfModels > = try await client. get ( path: path, validate: rule)
80-
81- return result. value
78+ let rule = [ Http . Validate. status ( . range( 200 ..< 299 ) ) ]
79+ do {
80+ let result : Http . Response < CollectionOfModels > = try await client. get ( path: path, validate: rule)
81+ return result. value
82+ } catch {
83+ throw ResponseError . check ( error)
84+ }
8285 }
8386
8487 /// Get a model
@@ -88,10 +91,14 @@ public struct ReplicateAPI{
8891 public func getModel( owner: String , name: String ) async throws -> Model {
8992
9093 let path = " models/ \( owner) / \( name) "
91- let rule = [ Http . Validate. status ( . range( 200 ..< 500 ) ) ]
92- let result : Http . Response < Model > = try await client. get ( path: path, validate: rule)
94+ let rule = [ Http . Validate. status ( . range( 200 ..< 299 ) ) ]
95+ do {
96+ let result : Http . Response < Model > = try await client. get ( path: path, validate: rule)
97+ return result. value
98+ } catch {
99+ throw ResponseError . check ( error)
100+ }
93101
94- return result. value
95102 }
96103
97104 /// Create prediction
@@ -141,13 +148,18 @@ public struct ReplicateAPI{
141148 by id : String
142149 ) async throws -> Prediction < Output > {
143150
144- let rule = [ Http . Validate. status ( . range( 200 ..< 500 ) ) ]
145- let result : Http . Response < Prediction < Output > > = try await client. get (
146- path: " predictions/ \( id) " ,
147- validate: rule
148- )
149-
150- return result. value
151+ let rule = [ Http . Validate. status ( . range( 200 ..< 299 ) ) ]
152+
153+ do {
154+ let result : Http . Response < Prediction < Output > > = try await client. get (
155+ path: " predictions/ \( id) " ,
156+ validate: rule
157+ )
158+
159+ return result. value
160+ } catch {
161+ throw ResponseError . check ( error)
162+ }
151163 }
152164
153165 // MARK: - Private
@@ -196,21 +208,26 @@ public struct ReplicateAPI{
196208 with body : HttpBody < Input >
197209 ) async throws -> Prediction < Output > {
198210
199- let rule = [ Http . Validate. status ( . range( 200 ..< 500 ) ) ]
200- let result : Http . Response < Prediction < Output > > = try await client. post (
201- path: " predictions " ,
202- body : body,
203- validate: rule
204- )
211+ let rule = [ Http . Validate. status ( . range( 200 ..< 299 ) ) ]
205212
206- return result. value
213+ do {
214+ let result : Http . Response < Prediction < Output > > = try await client. post (
215+ path: " predictions " ,
216+ body : body,
217+ validate: rule
218+ )
219+
220+ return result. value
221+ } catch {
222+ throw ResponseError . check ( error)
223+ }
207224 }
208225}
209226
210227// MARK: - File private -
211228
212229/// Client configuration type alias
213- fileprivate typealias ClientConfig = Http . Configuration < ReplicateAPI . JsonReader , JsonWriter >
230+ fileprivate typealias ClientConfig = Http . Configuration < JsonReader , JsonWriter >
214231
215232/// Client configuration
216233/// - Parameter endpoint: Replicate endpoint
@@ -220,7 +237,7 @@ fileprivate func clientCfg(baseURL: URL, apiKey: String)
220237 let session = URLSession ( configuration: sessionCfg ( apiKey) )
221238
222239 return . init(
223- reader: ReplicateAPI . JsonReader ( ) ,
240+ reader: JsonReader ( ) ,
224241 writer: JsonWriter ( ) ,
225242 baseURL: baseURL,
226243 session: session)
0 commit comments