hasura_connect icon indicating copy to clipboard operation
hasura_connect copied to clipboard

Unhandled Exception: ConnectionError: Websocket Error

Open SNPBharadwaj opened this issue 4 years ago • 5 comments
trafficstars

Hi facing this issues, unable to catch error when no network

Tried to catch it hear

Future<Snapshot<dynamic>> subscriptionRaw({
    @required String document,
    Map<String, HasuraResponse> variables,
  }) async {
    
    try {
      final Snapshot<dynamic> snapshot = await hasuraConnect.subscription(
          document, variables: variables);
      return snapshot;
    } on HasuraRequestError catch (error) {
      print(error);
      return null;
    } on ConnectionError catch (error) {
      print(error);
      return null;
    } on InvalidRequestError catch (error) {
      print(error);
      return null;
    } on InterceptorError catch (error) {
      print(error);
      return null;
    } on DatasourceError catch (error) {
      print(error);
      return null;
    } on HasuraApiError catch (error) {
      print(error);
      return null;
    } catch (error) {
      print(error);
      return null;
    }
  }

==========

final AutoDisposeStreamProvider<dynamic> categoriesRawStreamProvider =
    StreamProvider.autoDispose<dynamic>(
        (AutoDisposeProviderReference ref) async* {
  final HasuraService hasuraService = ref.read(hasuraServiceProvider);

  try {
    final Snapshot<dynamic> snapshot =
        await hasuraService.subscriptionRaw(document: r'''
               subscription fetchAllCourseCategories {
                  course_categories {
                    id
                    created_at
                    updated_at
                    name
                    short_info
                    featured_image
                    color
                  }
                }
               ''');
    // print(snapshot.rootStream.toList());
    ref.onDispose(() => snapshot.controller.sink.close());

    snapshot.controller.stream.handleError((onError) {
      print(onError);
    });

    try{
      snapshot.controller.stream.listen((event) {
        print(event);
      }, onError: (ee){
        print(ee);
      });
    }catch(ee){
      print(ee);
    }
    
    // await for (final dynamic value in snapshot.controller.stream) {
    //   yield value;
    // }
  } on ConnectionError catch (e) {
    print('ConnectionError');
    print(e);
    //do something else
  } catch (e) {
    print('asyncError');
    print(e);
  }
});

======= ALos

E/flutter (19382): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: ConnectionError: Websocket Error
E/flutter (19382): #0      HasuraConnect._renewConnector.<anonymous closure>.<anonymous closure> (package:hasura_connect/src/presenter/hasura_connect_base.dart:253:39)
E/flutter (19382): #1      Left.fold (package:dartz/src/either.dart:180:63)
E/flutter (19382): #2      HasuraConnect._renewConnector.<anonymous closure> (package:hasura_connect/src/presenter/hasura_connect_base.dart:253:27)
E/flutter (19382): <asynchronous suspension>
E/flutter (19382): #3      HasuraConnect._renewConnector.<anonymous closure> (package:hasura_connect/src/presenter/hasura_connect_base.dart)
E/flutter (19382): #4      None.fold (package:dartz/src/option.dart:202:59)
E/flutter (19382): #5      HasuraConnect._renewConnector (package:hasura_connect/src/presenter/hasura_connect_base.dart:250:18)
E/flutter (19382): #6      HasuraConnect._connect (package:hasura_connect/src/presenter/hasura_connect_base.dart:258:11)
E/flutter (19382): #7      HasuraConnect.subscription (package:hasura_connect/src/presenter/hasura_connect_base.dart:223:7)
E/flutter (19382): <asynchronous suspension>
E/flutter (19382): #8      HasuraService.subscriptionRaw (package:mybizmate_mobile_app/core/services/hasura/hasura_service.dart:204:42)
E/flutter (19382): #9      categoriesRawStreamProvider.<anonymous closure> (package:mybizmate_mobile_app/modules/home/home_screen.dart:72:29)
E/flutter (19382): <asynchronous suspension>
E/flutter (19382): #10     categoriesRawStreamProvider.<anonymous closure> (package:mybizmate_mobile_app/modules/home/home_screen.dart)
E/flutter (19382): #11     new AutoDisposeProviderBase.<anonymous closure> (package:riverpod/src/framework/auto_dispose.dart:36:28)
E/flutter (19382): #12     ProviderElement._runStateCreate (package:riverpod/src/framework/base_provider.dart:873:46)
E/flutter (19382): #13     ProviderElement.mount (package:riverpod/src/framework/base_provider.dart:801:7)
E/flutter (19382): #14     ProviderContainer.readProviderElement.<anonymous closure> (package:riverpod/src/framework/container.dart:308:13)
E/flutter (19382): #15     _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:140:29)
E/flutter (19382): #16     ProviderContainer.readProviderElement (package:riverpod/src/framework/container.dart:287:35)
E/flutter (19382): #17     ProviderContainer.listen (package:riverpod/src/framework/container.dart:152:14)
E/flutter (19382): #18     _ConsumerState._reader.<anonymous closure> (package:flutter_riverpod/src/consumer.dart:312:25)
E/flutter (19382): #19     _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:291:23)
E/flutter (19382): #20     _ConsumerState._reader (package:flutter_riverpod/src/consumer.dart:305:26)
E/flutter (19382): #21     HomeScreen.build (package:mybizmate_mobile_app/modules/home/home_screen.dart:129:14)
E/flutter (19382): #22     _ConsumerState.build (package:flutter_riverpod/src/consumer.dart:295:35)
E/flutter (19382): #23     StatefulElement.build (package:flutter/src/widgets/framework.dart:4744:28)
E/flutter (19382): #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4627:15)
E/flutter (19382): #25     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (19382): #26     Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (19382): #27     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter (19382): #28     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11)
E/flutter (19382): #29     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (19382): #30     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (19382): #31     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (19382): #32     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter (19382): #33     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (19382): #34     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (19382): #35     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (19382): #36     Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (19382): #37     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter (19382): #38     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (19382): #39     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (19382): #40     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (19382): #41     SingleChi

SNPBharadwaj avatar Feb 14 '21 17:02 SNPBharadwaj

unable to handle network error with subscription

SNPBharadwaj avatar Feb 26 '21 04:02 SNPBharadwaj

any solution for this error ?

thiagothg avatar Mar 28 '21 22:03 thiagothg

still no solution, waiting

SNPBharadwaj avatar Mar 29 '21 14:03 SNPBharadwaj

Queries work nicely but there seem to be a number of issues with subscriptions:

  • this one
  • https://github.com/Flutterando/hasura_connect/issues/90
  • https://github.com/Flutterando/hasura_connect/issues/67
  • https://github.com/Flutterando/hasura_connect/issues/83
  • https://github.com/Flutterando/hasura_connect/issues/82

barbalex avatar Jun 18 '21 15:06 barbalex

I guess the best way is using Interceptor

Bwolfs2 avatar Aug 12 '22 17:08 Bwolfs2