mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Add extra error reporting information in sentry errors
This commit is contained in:
parent
607d4b61ef
commit
8f02092731
51
lib/api.dart
51
lib/api.dart
@ -23,7 +23,7 @@ import 'package:inventree/widget/snacks.dart';
|
|||||||
*/
|
*/
|
||||||
class APIResponse {
|
class APIResponse {
|
||||||
|
|
||||||
APIResponse({this.url = "", this.method = "", this.statusCode = -1, this.data = const {}});
|
APIResponse({this.url = "", this.method = "", this.statusCode = -1, this.error = "", this.data = const {}});
|
||||||
|
|
||||||
int statusCode = -1;
|
int statusCode = -1;
|
||||||
|
|
||||||
@ -31,6 +31,10 @@ class APIResponse {
|
|||||||
|
|
||||||
String method = "";
|
String method = "";
|
||||||
|
|
||||||
|
String error = "";
|
||||||
|
|
||||||
|
String errorDetail = "";
|
||||||
|
|
||||||
dynamic data = {};
|
dynamic data = {};
|
||||||
|
|
||||||
// Request is "valid" if a statusCode was returned
|
// Request is "valid" if a statusCode was returned
|
||||||
@ -450,6 +454,7 @@ class InvenTreeAPI {
|
|||||||
return new APIResponse(
|
return new APIResponse(
|
||||||
url: url,
|
url: url,
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
|
error: "HttpClientRequest is null"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -667,34 +672,43 @@ class InvenTreeAPI {
|
|||||||
} else {
|
} else {
|
||||||
response.data = await responseToJson(_response) ?? {};
|
response.data = await responseToJson(_response) ?? {};
|
||||||
|
|
||||||
// Expected status code not returned
|
if (statusCode != null) {
|
||||||
if ((statusCode != null) && (statusCode != _response.statusCode)) {
|
|
||||||
showStatusCodeError(_response.statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Report any server errors
|
// Expected status code not returned
|
||||||
if (_response.statusCode >= 500) {
|
if (statusCode != _response.statusCode) {
|
||||||
sentryReportMessage(
|
showStatusCodeError(_response.statusCode);
|
||||||
"Server error",
|
}
|
||||||
context: {
|
|
||||||
"url": request.uri.toString(),
|
// Report any server errors
|
||||||
"method": request.method,
|
if (_response.statusCode >= 500) {
|
||||||
"statusCode": _response.statusCode.toString(),
|
sentryReportMessage(
|
||||||
"requestHeaders": request.headers.toString(),
|
"Server error",
|
||||||
"responseHeaders": _response.headers.toString(),
|
context: {
|
||||||
"responseData": response.data.toString(),
|
"url": request.uri.toString(),
|
||||||
}
|
"method": request.method,
|
||||||
);
|
"statusCode": _response.statusCode.toString(),
|
||||||
|
"requestHeaders": request.headers.toString(),
|
||||||
|
"responseHeaders": _response.headers.toString(),
|
||||||
|
"responseData": response.data.toString(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} on SocketException catch (error) {
|
} on SocketException catch (error) {
|
||||||
showServerError(L10().connectionRefused, error.toString());
|
showServerError(L10().connectionRefused, error.toString());
|
||||||
|
response.error = "SocketException";
|
||||||
|
response.errorDetail = error.toString();
|
||||||
|
|
||||||
} on TimeoutException {
|
} on TimeoutException {
|
||||||
showTimeoutError();
|
showTimeoutError();
|
||||||
|
response.error = "TimeoutException";
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
showServerError(L10().serverError, error.toString());
|
showServerError(L10().serverError, error.toString());
|
||||||
sentryReportError(error, stackTrace);
|
sentryReportError(error, stackTrace);
|
||||||
|
response.error = "UnknownError";
|
||||||
|
response.errorDetail = error.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@ -754,6 +768,7 @@ class InvenTreeAPI {
|
|||||||
return new APIResponse(
|
return new APIResponse(
|
||||||
url: url,
|
url: url,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
error: "HttpClientRequest is null",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +114,8 @@ class BarcodeHandler {
|
|||||||
"url": url,
|
"url": url,
|
||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"valid": response.isValid().toString(),
|
"valid": response.isValid().toString(),
|
||||||
|
"error": response.error,
|
||||||
|
"errorDetail": response.errorDetail,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (response.data.containsKey('error')) {
|
} else if (response.data.containsKey('error')) {
|
||||||
|
@ -162,6 +162,8 @@ class InvenTreeModel {
|
|||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"data": response.data?.toString() ?? "null",
|
"data": response.data?.toString() ?? "null",
|
||||||
"valid": response.isValid().toString(),
|
"valid": response.isValid().toString(),
|
||||||
|
"error": response.error,
|
||||||
|
"errorDetail": response.errorDetail,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -230,7 +232,9 @@ class InvenTreeModel {
|
|||||||
"url": url,
|
"url": url,
|
||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"data": response.data?.toString() ?? "null",
|
"data": response.data?.toString() ?? "null",
|
||||||
"valid": response.isValid().toString()
|
"valid": response.isValid().toString(),
|
||||||
|
"error": response.error,
|
||||||
|
"errorDetail": response.errorDetail,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -270,6 +274,8 @@ class InvenTreeModel {
|
|||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"data": response.data?.toString() ?? "null",
|
"data": response.data?.toString() ?? "null",
|
||||||
"valid": response.isValid().toString(),
|
"valid": response.isValid().toString(),
|
||||||
|
"error": response.error,
|
||||||
|
"errorDetail": response.errorDetail,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user