mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +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:
parent
75e0a69eab
commit
dacbf880da
31
lib/api.dart
31
lib/api.dart
@ -1018,18 +1018,25 @@ class InvenTreeAPI {
|
||||
if (_response.statusCode >= 500) {
|
||||
showStatusCodeError(url, _response.statusCode);
|
||||
|
||||
sentryReportMessage(
|
||||
"Server error",
|
||||
context: {
|
||||
"url": request.uri.toString(),
|
||||
"method": request.method,
|
||||
"statusCode": _response.statusCode.toString(),
|
||||
"requestHeaders": request.headers.toString(),
|
||||
"responseHeaders": _response.headers.toString(),
|
||||
"responseData": response.data.toString(),
|
||||
}
|
||||
);
|
||||
|
||||
// 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(
|
||||
"Server error",
|
||||
context: {
|
||||
"url": request.uri.toString(),
|
||||
"method": request.method,
|
||||
"statusCode": _response.statusCode.toString(),
|
||||
"requestHeaders": request.headers.toString(),
|
||||
"responseHeaders": _response.headers.toString(),
|
||||
"responseData": response.data.toString(),
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (ignoreResponse) {
|
||||
|
@ -234,10 +234,23 @@ class InvenTreeModel {
|
||||
return {};
|
||||
}
|
||||
|
||||
/*
|
||||
* Report error information to sentry, when a model operation fails.
|
||||
*/
|
||||
Future<void> reportModelError(String title, APIResponse response, {Map<String, String> context = const {}}) async {
|
||||
|
||||
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) {
|
||||
dataString = dataString.substring(0, 500);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
print("----- Sentry Intercepted error: $error -----");
|
||||
@ -166,6 +169,22 @@ Future<void> sentryReportError(String source, dynamic error, dynamic stackTrace,
|
||||
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 app_info = await getAppInfo();
|
||||
final device_info = await getDeviceInfo();
|
||||
|
Loading…
x
Reference in New Issue
Block a user