postgrest-swift
postgrest-swift copied to clipboard
`PostgrestError`s not reported correctly
Bug report
Describe the bug
I noticed that I never see the actual error that Postgrest returns, but instead get a generic statusCode: 400 error. I had to set breakpoints and print the response to see what was actually wrong.
After some digging through the code, I noticed that the problem is that the validateResponse delegate method from APIClientDelegate is never called on PostgrestAPIClientDelegate. This is because the supabase-swift package adds its own delegate, resulting in a MultiAPIClientDelegate being set.
So far so good, but since supbase-swift does not implement validateResponse the default implementation from the Get package gets called, which throws this generic error and the custom implementation from PostgrestAPIClientDelegate never gets called.
The easy way to fix this, is to give PostgrestAPIClientDelegate precedence to whatever delegate is passed to PostgrestClient.init, but I could imagine this having other unforeseen consequences.
The change would simply be to change the line 32 in PostgrestClient.swift from this:
$0.delegate = MultiAPIClientDelegate([customDelegate, PostgrestAPIClientDelegate()])
to this:
$0.delegate = MultiAPIClientDelegate([PostgrestAPIClientDelegate(), customDelegate])
Alternatively, the SupabaseClient could implement the validateResponse method and just not do any validation.
What do you think? I'm happy to submit a PR, but don't feel either approach is perfect.
Hey @leoMehlig thanks for opening this.
I'm currently working on the removal of the Get library as a dependency on https://github.com/supabase-community/postgrest-swift/pull/43, this issue will be fixed.