supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
3.26k stars 269 forks source link

Bug/Proposal: try catch not working on supabase api functions #978

Open Shidoengie opened 9 months ago

Shidoengie commented 9 months ago

Bug report

Describe the bug

This started when i tried using a try catch on the auth.signUp function but finding out that even though a error is returned catch is never called I found out that this aplies to a lot of functions and its pretty bad for DX

To Reproduce

try {
  let response = await supabase.auth.signUp({email,password});
  return {success:true};
} catch(err) {
  return {sucess:false}
}

Expected behavior

API functions should return responses and throw errors instead of having a error field that may or may not be null.

System information

Nelhoa commented 8 months ago

I think that the whole supabase-js api is working that way. And I personnaly disliked it at first, but now its seem perfect to me. Just create your own wrappers to check {data, error} and eventauly throw your own Error class.