supabase-community / postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
https://supabase.io
Apache License 2.0
170 stars 27 forks source link

In cases of non 20x responses, return an error from Execute() #11

Closed intabulas closed 3 years ago

intabulas commented 3 years ago

What kind of change does this PR introduce?

This PR allows Execute() to actually return an error if a non 20x response is received from supabase.

What is the current behavior?

Currently, if an error is received, Execute() return a nil error and the response from supabase. This then requires the user to determine if an error occurred by the contents of the response bytes

ex:

resp, err := client.From("sometable").Insert(document, false, "", "", "").Execute()
// error will always be nil with current behavior, if (for example) sometable doesnt exist
if err != nil {
  // nothing to handle
}

What is the new behavior?

resp, err := client.From("sometable").Insert(document, false, "", "", "").Execute()
// error will not be nil if any non 20x error is returned from supabase
if err != nil {
  // print, or log, or return etc
  fmt.Printf("ERROR: %s\n", err)
}

Additional context

I made two decisions that could be changed. The first was to include Hint and Details in the response struct, even though they are not used. The second was do do >= 300 vs 400 on the error check,

yusufpapurcu commented 3 years ago

I'm on vacation, I'll test it when I'm available. Thanks for support 👍

intabulas commented 3 years ago

sorry about the force push, was working on #12 and realized PR was still open