Open bverhagen opened 10 months ago
I just realized that, around the same time, I switched on fatal and async error recording for Firebase Crashlytics (which may explain why I did not see this happen with hasura_connect
):
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};
I assume it is the async error recording that is the culprit here. Still, is there a way to catch it?
In the meantime I found this: https://github.com/dart-lang/web_socket_channel/issues/38.
I am going to test whether the suggested solution of awaiting socket.ready will allow me to catch the error in the channelGenerator callback.
Preliminary testing seems to indicate this fixes it for initial connection errors:
channelGenerator: () async {
while (true) {
final socket = WebSocketChannel.connect(
Uri.parse("wss://$apiDomain/v1/graphql"));
try {
await socket.ready;
developer
.log("Successfully connected with websocket to '$apiDomain'!");
return socket;
} catch (e, stacktrace) {
developer.log("Error connecting to websocket: $e");
await Future.delayed(const Duration(seconds: 5));
}
}
}
Shouldn't the default channelGenerator be robust against this to?
Additionally, returning the errored socket, also results in an uncaught async error later on in its usage.
I switched to gql_websocket_link to connect to my GraphQL backend (before I used
hasura_connect
). Since this switch, Firebase Crashlytics reports:I think this is due to the connection being interrupted by me switching off mobile and wifi connectivity. So, obviously, the actual error makes sense. However, I don't think the app should crash nor be reported on Crashlytics when I do.
Currently, the connection is implemented as:
I thought switching to the channelGenerator argument (with a
null
url), I would be able to wrap the WebSocketChannelException in a try/catch clause to avoid this. However, somehow, the SocketException keeps on escaping my try/catch and hence keeps on crashing the app:My
main/AndroidManifest.xml
contains theandroid.permission.INTERNET
permission:Even though I really doubt I am the first one to see this issue, I do not find any related issues. Can you point me to an example or the typical solution to fix this?