supabase / postgrest-dart

Dart client for PostgREST
https://supabase.com
MIT License
136 stars 38 forks source link

Update postgrest.dart #17

Closed goldcoders closed 3 years ago

goldcoders commented 3 years ago

Expose PostgrestError so we can use it on a try catch block

import 'package:postgrest/postgrest.dart' show PostgrestError;
try {
      var response =
          await client.from('features').insert(feature.toMap()).execute();
      if (response.error != null) {
      // at the moment we can only fetch the error on this code 
        print( "ERROR ${response.error.code}", "${response.error.message}");
      }
    } on PostgrestError {
      // even after exposing this is not trigger
    } catch (e, s) {
     // error and stackstrace cannot be catch ?
      print("${s.toString()}");
    }
goldcoders commented 3 years ago

To make it clear this PR, still cant Catch the PostgresError Exception...

I need to dig deeper on to the code, but i hope the supabase team , can show the right direction...

Using Try catch block is useless when using supabaseClient

I Hope the Error Would Bubble Up to the The Top Level ERROR HANDLER. which can be caught by the try catch block....

It seems that the supabase client is not throwing any error, as supposed to be so the dev can handle it for Example a Token Expiration is hard to Detect...

Supposed to be when a User Token Expired It Would be intercepted when an exception is thrown. and that would be handle to trigger a Token refresh...

phamhieu commented 3 years ago

Hi @goldcoders, I deployed new version 0.0.6:

You can check the example for try/catch code. Let me know if anything is unclear