Skip to content

Commit

Permalink
Merge pull request #760 from cake-tech/exception_handler_enhancements
Browse files Browse the repository at this point in the history
Exception Handler Enhancements
  • Loading branch information
OmarHatem28 authored Feb 3, 2023
2 parents f5fa87a + d858059 commit a2cb99a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/anypay/anypay_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>;
throw Exception(decodedBody['message'] as String);
throw Exception(decodedBody['message'] as String? ?? 'Unexpected response\nError code: 400');
}

if (response.statusCode != 200) {
Expand Down
9 changes: 5 additions & 4 deletions lib/utils/exception_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ExceptionHandler {
}

static void onError(FlutterErrorDetails errorDetails) {
if (_isErrorFromUser(errorDetails.exception.toString())) {
if (_ignoreError(errorDetails.exception.toString())) {
return;
}

Expand Down Expand Up @@ -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)
}
}

0 comments on commit a2cb99a

Please sign in to comment.