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( return Client(
clientName, clientName,
httpClient: httpClient: CustomHttpClient.createHTTPClient(),
PlatformInfos.isAndroid ? CustomHttpClient.createHTTPClient() : null,
verificationMethods: { verificationMethods: {
KeyVerificationMethod.numbers, KeyVerificationMethod.numbers,
if (kIsWeb || PlatformInfos.isMobile || PlatformInfos.isLinux) if (kIsWeb || PlatformInfos.isMobile || PlatformInfos.isLinux)

@ -3,9 +3,15 @@ import 'dart:io';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:http/io_client.dart'; import 'package:http/io_client.dart';
import 'package:http/retry.dart' as retry;
import 'package:fluffychat/config/isrg_x1.dart'; 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 { class CustomHttpClient {
static HttpClient customHttpClient(String? cert) { static HttpClient customHttpClient(String? cert) {
final context = SecurityContext.defaultContext; final context = SecurityContext.defaultContext;
@ -26,5 +32,9 @@ class CustomHttpClient {
return HttpClient(context: context); 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/flutter_highlighter.dart';
import 'package:flutter_highlighter/themes/shades-of-purple.dart'; import 'package:flutter_highlighter/themes/shades-of-purple.dart';
import 'package:http/http.dart' as http;
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
@ -20,6 +21,14 @@ class ErrorReporter {
const ErrorReporter(this.context, [this.message]); const ErrorReporter(this.context, [this.message]);
static const Set<Type> ingoredTypes = {
IOException,
http.ClientException,
SocketException,
TlsException,
HandshakeException,
};
Future<File> _getTemporaryErrorLogFile() async { Future<File> _getTemporaryErrorLogFile() async {
final tempDir = await getTemporaryDirectory(); final tempDir = await getTemporaryDirectory();
return File(path.join(tempDir.path, 'error_log.txt')); return File(path.join(tempDir.path, 'error_log.txt'));
@ -29,6 +38,7 @@ class ErrorReporter {
Object error, [ Object error, [
StackTrace? stackTrace, StackTrace? stackTrace,
]) async { ]) async {
if (ingoredTypes.contains(error.runtimeType)) return;
final file = await _getTemporaryErrorLogFile(); final file = await _getTemporaryErrorLogFile();
if (await file.exists()) await file.delete(); if (await file.exists()) await file.delete();
await file.writeAsString( await file.writeAsString(
@ -40,11 +50,12 @@ class ErrorReporter {
final file = await _getTemporaryErrorLogFile(); final file = await _getTemporaryErrorLogFile();
if (!(await file.exists())) return; if (!(await file.exists())) return;
final content = await file.readAsString(); final content = await file.readAsString();
_onErrorCallback(content); _onErrorCallback(content);
await file.delete();
} }
void onErrorCallback(Object error, [StackTrace? stackTrace]) { void onErrorCallback(Object error, [StackTrace? stackTrace]) {
if (ingoredTypes.contains(error.runtimeType)) return;
Logs().e(message ?? 'Error caught', error, stackTrace); Logs().e(message ?? 'Error caught', error, stackTrace);
final text = '$error\n${stackTrace ?? ''}'; final text = '$error\n${stackTrace ?? ''}';
return _onErrorCallback(text); return _onErrorCallback(text);

Loading…
Cancel
Save