2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Improve error handling and reporting (#190)

* Prevent duplicate reporting of errors to sentry

* Prevent error message upload on some server error codes

* Filter out some common errors we are not interested in
This commit is contained in:
Oliver 2022-07-26 15:57:16 +10:00 committed by GitHub
parent 75e0a69eab
commit dacbf880da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 12 deletions

View File

@ -1018,6 +1018,12 @@ class InvenTreeAPI {
if (_response.statusCode >= 500) { if (_response.statusCode >= 500) {
showStatusCodeError(url, _response.statusCode); showStatusCodeError(url, _response.statusCode);
// Some server errors are not ones for us to worry about!
switch (_response.statusCode) {
case 502: // Bad gateway
case 504: // Gateway timeout
break;
default: // Any other error code
sentryReportMessage( sentryReportMessage(
"Server error", "Server error",
context: { context: {
@ -1029,7 +1035,8 @@ class InvenTreeAPI {
"responseData": response.data.toString(), "responseData": response.data.toString(),
} }
); );
break;
}
} else { } else {
if (ignoreResponse) { if (ignoreResponse) {

View File

@ -234,10 +234,23 @@ class InvenTreeModel {
return {}; return {};
} }
/*
* Report error information to sentry, when a model operation fails.
*/
Future<void> reportModelError(String title, APIResponse response, {Map<String, String> context = const {}}) async { Future<void> reportModelError(String title, APIResponse response, {Map<String, String> context = const {}}) async {
String dataString = response.data?.toString() ?? "null"; String dataString = response.data?.toString() ?? "null";
// If the response has "errorDetail" set, then the error has already been handled, and there is no need to continue
if (response.errorDetail.isNotEmpty) {
return;
}
// If the response status code indicates a server error, then this has already been reported
if (response.statusCode >= 500) {
return;
}
if (dataString.length > 500) { if (dataString.length > 500) {
dataString = dataString.substring(0, 500); dataString = dataString.substring(0, 500);
} }

View File

@ -145,6 +145,9 @@ Future<bool> sentryReportMessage(String message, {Map<String, String>? context})
} }
/*
* Report an error message to sentry.io
*/
Future<void> sentryReportError(String source, dynamic error, dynamic stackTrace, {Map<String, String> context = const {}}) async { Future<void> sentryReportError(String source, dynamic error, dynamic stackTrace, {Map<String, String> context = const {}}) async {
print("----- Sentry Intercepted error: $error -----"); print("----- Sentry Intercepted error: $error -----");
@ -166,6 +169,22 @@ Future<void> sentryReportError(String source, dynamic error, dynamic stackTrace,
return; return;
} }
// Some errors are outside our control, and we do not want to "pollute" the uploaded data
if (source == "FlutterError.onError") {
String errorString = error.toString();
// Missing media file
if (errorString.contains("HttpException") && errorString.contains("404") && errorString.contains("/media/")) {
return;
}
// Local file system exception
if (errorString.contains("FileSystemException")) {
return;
}
}
final server_info = getServerInfo(); final server_info = getServerInfo();
final app_info = await getAppInfo(); final app_info = await getAppInfo();
final device_info = await getDeviceInfo(); final device_info = await getDeviceInfo();