mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Upload custom message when server returns error code >= 500
This commit is contained in:
parent
01e0dd5dce
commit
f6c8d9a449
43
lib/api.dart
43
lib/api.dart
@ -525,6 +525,18 @@ class InvenTreeAPI {
|
||||
print("Data:");
|
||||
print(responseData);
|
||||
|
||||
// Server error
|
||||
if (response.statusCode >= 500) {
|
||||
sentryReportMessage(
|
||||
"Server error on PATCH request",
|
||||
context: {
|
||||
"url": _url,
|
||||
"statusCode": "${response.statusCode}",
|
||||
"data": responseData.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -660,6 +672,18 @@ class InvenTreeAPI {
|
||||
print("Data:");
|
||||
print(responseData);
|
||||
|
||||
// Server error
|
||||
if (response.statusCode >= 500) {
|
||||
sentryReportMessage(
|
||||
"Server error on POST request",
|
||||
context: {
|
||||
"url": _url,
|
||||
"statusCode": "${response.statusCode}",
|
||||
"data": responseData.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -863,15 +887,28 @@ class InvenTreeAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
var responseData = await responseToJson(response);
|
||||
|
||||
// Check the status code of the response
|
||||
if (response.statusCode != expectedStatusCode) {
|
||||
showStatusCodeError(response.statusCode);
|
||||
|
||||
// Server error
|
||||
if (response.statusCode >= 500) {
|
||||
sentryReportMessage(
|
||||
"Server error on GET request",
|
||||
context: {
|
||||
"url": url,
|
||||
"statusCode": "${response.statusCode}",
|
||||
"data": responseData.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var data = await responseToJson(response);
|
||||
|
||||
return data;
|
||||
return responseData;
|
||||
}
|
||||
|
||||
Map<String, String> defaultHeaders() {
|
||||
|
@ -84,6 +84,40 @@ bool isInDebugMode() {
|
||||
return inDebugMode;
|
||||
}
|
||||
|
||||
Future<bool> sentryReportMessage(String message, {Map<String, String>? context}) async {
|
||||
|
||||
final server_info = getServerInfo();
|
||||
final app_info = await getAppInfo();
|
||||
final device_info = await getDeviceInfo();
|
||||
|
||||
print("Sending user message to Sentry: ${message}");
|
||||
|
||||
if (isInDebugMode()) {
|
||||
|
||||
print('----- In dev mode. Not sending message to Sentry.io -----');
|
||||
return true;
|
||||
}
|
||||
|
||||
Sentry.configureScope((scope) {
|
||||
scope.setExtra("server", server_info);
|
||||
scope.setExtra("app", app_info);
|
||||
scope.setExtra("device", device_info);
|
||||
|
||||
if (context != null) {
|
||||
scope.setExtra("context", context);
|
||||
}
|
||||
});
|
||||
|
||||
final sentryId = await Sentry.captureMessage(message).catchError((error) {
|
||||
print("Error uploading sentry messages...");
|
||||
print(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
return sentryId != null;
|
||||
}
|
||||
|
||||
|
||||
Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
|
||||
|
||||
print('----- Sentry Intercepted error: $error -----');
|
||||
@ -115,27 +149,3 @@ Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
|
||||
print("Uploaded information to Sentry.io : ${response.toString()}");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Future<bool> sentryReportMessage(String message) async {
|
||||
|
||||
final server_info = getServerInfo();
|
||||
final app_info = await getAppInfo();
|
||||
final device_info = await getDeviceInfo();
|
||||
|
||||
print("Sending user message to Sentry");
|
||||
|
||||
Sentry.configureScope((scope) {
|
||||
scope.setExtra("server", server_info);
|
||||
scope.setExtra("app", app_info);
|
||||
scope.setExtra("device", device_info);
|
||||
});
|
||||
|
||||
final sentryId = await Sentry.captureMessage(message).catchError((error) {
|
||||
print("Error uploading sentry messages...");
|
||||
print(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
return sentryId != null;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user