nhost-js-sdk icon indicating copy to clipboard operation
nhost-js-sdk copied to clipboard

API Response object

Open joshua1 opened this issue 3 years ago • 2 comments

Hi @elitan , I think it would be nice to have the public methods of this api return an object of {T,Error} , or a tuple of [T,Error] like you have with supabase, instead of throwing within the catch block . I think the experience is better and provides better user experience .

try{
       const T=docSomeWork(args);       
      
      if(T condition not met)
      throw 'T is not valid or something'; //can still throw exception here 
     return {T,null};
 }catch(error){
     return {null,error}
}

when calling this API method , i can then

const {T,error}=await nhostClient....();
if(error) {
  //log, friendly alert message etc
return;
}
//or use result

joshua1 avatar Sep 30 '21 09:09 joshua1

Totally agree and we do have that for Nhost v2 which is due to go public in the coming days. Some code is already open if you want to check it out:

https://github.com/nhost/hasura-auth-js/blob/main/src/hasura-auth-api.ts https://github.com/nhost/hasura-auth-js/blob/main/src/hasura-auth-client.ts

elitan avatar Sep 30 '21 09:09 elitan

@elitan the links are 404. Good to hear this is in place in the NHost API and client. I thought NHost uses this SDK too?

joshua1 avatar Sep 30 '21 11:09 joshua1