From d85805902d7d5b5c443c35d1893d4e159be59406 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 3 Feb 2023 14:44:13 +0200 Subject: [PATCH] - Ignore Socket Exception "bad file descriptor" - Add nullability to anypay API response failure [skip ci] --- lib/anypay/anypay_api.dart | 2 +- lib/utils/exception_handler.dart | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/anypay/anypay_api.dart b/lib/anypay/anypay_api.dart index 5eb9e460b..679d0eabf 100644 --- a/lib/anypay/anypay_api.dart +++ b/lib/anypay/anypay_api.dart @@ -80,7 +80,7 @@ class AnyPayApi { final response = await post(Uri.parse(uri), headers: headers, body: utf8.encode(json.encode(body))); if (response.statusCode == 400) { final decodedBody = json.decode(response.body) as Map; - throw Exception(decodedBody['message'] as String); + throw Exception(decodedBody['message'] as String? ?? 'Unexpected response\nError code: 400'); } if (response.statusCode != 200) { diff --git a/lib/utils/exception_handler.dart b/lib/utils/exception_handler.dart index b5d57eba1..889f86c63 100644 --- a/lib/utils/exception_handler.dart +++ b/lib/utils/exception_handler.dart @@ -59,7 +59,7 @@ class ExceptionHandler { } static void onError(FlutterErrorDetails errorDetails) { - if (_isErrorFromUser(errorDetails.exception.toString())) { + if (_ignoreError(errorDetails.exception.toString())) { return; } @@ -97,8 +97,9 @@ class ExceptionHandler { ); } - /// User related errors to be added as exceptions here to not report - static bool _isErrorFromUser(String error) { - return error.contains("Software caused connection abort"); // User connection issue + /// Ignore User related errors or system errors + static bool _ignoreError(String error) { + return error.contains("errno = 103") || // SocketException: Software caused connection abort + error.contains("errno = 9"); // SocketException: Bad file descriptor (iOS socket exception) } }