supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

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

Open Shidoengie opened this issue 1 year ago • 1 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

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

  • OS: Windows "@supabase/supabase-js": "^2.38.5"
  • Version of Node.js: v21.6.2

Shidoengie avatar Feb 16 '24 13:02 Shidoengie

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.

Nelhoa avatar Feb 26 '24 15:02 Nelhoa