diff --git a/lib/utils/client_manager.dart b/lib/utils/client_manager.dart index ddda56824..5c5a07663 100644 --- a/lib/utils/client_manager.dart +++ b/lib/utils/client_manager.dart @@ -106,8 +106,7 @@ abstract class ClientManager { return Client( clientName, - httpClient: - PlatformInfos.isAndroid ? CustomHttpClient.createHTTPClient() : null, + httpClient: CustomHttpClient.createHTTPClient(), verificationMethods: { KeyVerificationMethod.numbers, if (kIsWeb || PlatformInfos.isMobile || PlatformInfos.isLinux) diff --git a/lib/utils/custom_http_client.dart b/lib/utils/custom_http_client.dart index 479e5edb5..b0a3dcb28 100644 --- a/lib/utils/custom_http_client.dart +++ b/lib/utils/custom_http_client.dart @@ -3,9 +3,15 @@ import 'dart:io'; import 'package:http/http.dart' as http; import 'package:http/io_client.dart'; +import 'package:http/retry.dart' as retry; import 'package:fluffychat/config/isrg_x1.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; +/// Custom Client to add an additional certificate. This is for the isrg X1 +/// certificate which is needed for LetsEncrypt certificates. It is shipped +/// on Android since OS version 7.1. As long as we support older versions we +/// still have to ship this certificate by ourself. class CustomHttpClient { static HttpClient customHttpClient(String? cert) { final context = SecurityContext.defaultContext; @@ -26,5 +32,9 @@ class CustomHttpClient { return HttpClient(context: context); } - static http.Client createHTTPClient() => IOClient(customHttpClient(ISRG_X1)); + static http.Client createHTTPClient() => retry.RetryClient( + PlatformInfos.isAndroid + ? IOClient(customHttpClient(ISRG_X1)) + : http.Client(), + ); } diff --git a/lib/utils/error_reporter.dart b/lib/utils/error_reporter.dart index e68f5cdea..6a8b0f866 100644 --- a/lib/utils/error_reporter.dart +++ b/lib/utils/error_reporter.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_highlighter/flutter_highlighter.dart'; import 'package:flutter_highlighter/themes/shades-of-purple.dart'; +import 'package:http/http.dart' as http; import 'package:matrix/matrix.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; @@ -20,6 +21,14 @@ class ErrorReporter { const ErrorReporter(this.context, [this.message]); + static const Set ingoredTypes = { + IOException, + http.ClientException, + SocketException, + TlsException, + HandshakeException, + }; + Future _getTemporaryErrorLogFile() async { final tempDir = await getTemporaryDirectory(); return File(path.join(tempDir.path, 'error_log.txt')); @@ -29,6 +38,7 @@ class ErrorReporter { Object error, [ StackTrace? stackTrace, ]) async { + if (ingoredTypes.contains(error.runtimeType)) return; final file = await _getTemporaryErrorLogFile(); if (await file.exists()) await file.delete(); await file.writeAsString( @@ -40,11 +50,12 @@ class ErrorReporter { final file = await _getTemporaryErrorLogFile(); if (!(await file.exists())) return; final content = await file.readAsString(); - _onErrorCallback(content); + await file.delete(); } void onErrorCallback(Object error, [StackTrace? stackTrace]) { + if (ingoredTypes.contains(error.runtimeType)) return; Logs().e(message ?? 'Error caught', error, stackTrace); final text = '$error\n${stackTrace ?? ''}'; return _onErrorCallback(text);