- Ignore Socket Exception "bad file descriptor" - Add nullability to anypay API response failure [skip ci]

- Ignore Socket Exception "bad file descriptor" - Add nullability to anypay API response failure [skip ci]

OmarHatem committed Feb 3, 2023 at 14:44 UTC d85805902d7d5b5c443c35d1893d4e159be59406
2 files changed +6 -5
lib/anypay/anypay_api.dart
+1 -1
@@ -80,7 +80,7 @@ class AnyPayApi {
80 final response = await post(Uri.parse(uri), headers: headers, body: utf8.encode(json.encode(body)));
81 if (response.statusCode == 400) {
82 final decodedBody = json.decode(response.body) as Map<String, dynamic>;
83 - throw Exception(decodedBody['message'] as String);
83 + throw Exception(decodedBody['message'] as String? ?? 'Unexpected response\nError code: 400');
84 }
85
86 if (response.statusCode != 200) {
lib/utils/exception_handler.dart
+5 -4
@@ -59,7 +59,7 @@ class ExceptionHandler {
59 }
60
61 static void onError(FlutterErrorDetails errorDetails) {
62 - if (_isErrorFromUser(errorDetails.exception.toString())) {
62 + if (_ignoreError(errorDetails.exception.toString())) {
63 return;
64 }
65
@@ -97,8 +97,9 @@ class ExceptionHandler {
97 );
98 }
99
100 - /// User related errors to be added as exceptions here to not report
101 - static bool _isErrorFromUser(String error) {
102 - return error.contains("Software caused connection abort"); // User connection issue
100 + /// Ignore User related errors or system errors
101 + static bool _ignoreError(String error) {
102 + return error.contains("errno = 103") || // SocketException: Software caused connection abort
103 + error.contains("errno = 9"); // SocketException: Bad file descriptor (iOS socket exception)
104 }
105 }