fix: Use retry http client

pull/2048/head
Christian Kußowski 3 months ago
parent c9e4c2aa11
commit 2797974d45
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -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)

@ -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(),
);
}

@ -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<Type> ingoredTypes = {
IOException,
http.ClientException,
SocketException,
TlsException,
HandshakeException,
};
Future<File> _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);

Loading…
Cancel
Save