Closed
Description
Problem: Unless I'm doing something wrong, I think it's not possible for a consumer to override the default implementation of the APIClientDelegate
validateResponse
function on the SupabaseClient
, which will cause this code to always be executed:
func client(_ client: APIClient, validateResponse response: HTTPURLResponse, data: Data, task: URLSessionTask) throws {
guard (200..<300).contains(response.statusCode) else {
throw APIError.unacceptableStatusCode(response.statusCode)
}
}
** This hides all the good Postgres details that are helpful for debugging. **
Describe the solution you'd like
I tried to override SupabaseClient
outside of this module inside my own module, but it seems like the default implementation is always overriding (again unless I'm doing something wrong).
I ended up having to fork to include this (though a proper way may be to have SupabaseClient.init(...)
allow for its own delegate an follow the MultiAPIClientDelegate
compose pattern that the PostgresClient
is using.
extension SupabaseClient: APIClientDelegate {
public func client(_: APIClient, willSendRequest request: inout URLRequest) async throws {
request = await adapt(request: request)
}
public func client(_ client: APIClient, validateResponse response: HTTPURLResponse, data: Data, task: URLSessionTask) throws {
if 200 ..< 300 ~= response.statusCode {
return
}
throw try client.configuration.decoder.decode(PostgrestError.self, from: data)
}
}