Merge pull request #760 from cake-tech/exception_handler_enhancements

Exception Handler Enhancements
This commit is contained in:
Omar Hatem 2023-02-03 18:23:34 +02:00 committed by GitHub
commit a2cb99a331
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

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

View file

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