nhost-js-sdk
nhost-js-sdk copied to clipboard
API Response object
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
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 the links are 404. Good to hear this is in place in the NHost API and client. I thought NHost uses this SDK too?