fix: Use retry http client

This commit is contained in:
Christian Kußowski 2025-07-27 07:44:48 +02:00
commit 2797974d45
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
3 changed files with 24 additions and 4 deletions

View file

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