mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Merge pull request #128 from inventree/sentry-improvements
Sentry improvements
This commit is contained in:
commit
e47d88a4bb
@ -332,10 +332,6 @@ class InvenTreeAPI {
|
|||||||
if (!address.endsWith("/")) {
|
if (!address.endsWith("/")) {
|
||||||
address = address + "/";
|
address = address + "/";
|
||||||
}
|
}
|
||||||
/* TODO: Better URL validation
|
|
||||||
* - If not a valid URL, return error
|
|
||||||
* - If no port supplied, append a default port
|
|
||||||
*/
|
|
||||||
|
|
||||||
_BASE_URL = address;
|
_BASE_URL = address;
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class BarcodeHandler {
|
|||||||
body: {
|
body: {
|
||||||
"barcode": barcode,
|
"barcode": barcode,
|
||||||
},
|
},
|
||||||
expectedStatusCode: 200
|
expectedStatusCode: null, // Do not show an error on "unexpected code"
|
||||||
);
|
);
|
||||||
|
|
||||||
_controller?.resumeCamera();
|
_controller?.resumeCamera();
|
||||||
@ -90,7 +90,7 @@ class BarcodeHandler {
|
|||||||
|
|
||||||
// We want to know about this one!
|
// We want to know about this one!
|
||||||
await sentryReportMessage(
|
await sentryReportMessage(
|
||||||
"BarcodeHandler.processBarcode returned strange value",
|
"BarcodeHandler.processBarcode returned unexpected value",
|
||||||
context: {
|
context: {
|
||||||
"data": response.data?.toString() ?? "null",
|
"data": response.data?.toString() ?? "null",
|
||||||
"barcode": barcode,
|
"barcode": barcode,
|
||||||
@ -99,9 +99,10 @@ class BarcodeHandler {
|
|||||||
"valid": response.isValid().toString(),
|
"valid": response.isValid().toString(),
|
||||||
"error": response.error,
|
"error": response.error,
|
||||||
"errorDetail": response.errorDetail,
|
"errorDetail": response.errorDetail,
|
||||||
|
"overlayText": getOverlayText(context),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (data.containsKey("error")) {
|
} else if ((response.statusCode >= 400) || data.containsKey("error")) {
|
||||||
onBarcodeUnknown(context, data);
|
onBarcodeUnknown(context, data);
|
||||||
} else if (data.containsKey("success")) {
|
} else if (data.containsKey("success")) {
|
||||||
onBarcodeMatched(context, data);
|
onBarcodeMatched(context, data);
|
||||||
|
@ -233,6 +233,32 @@ class InvenTreeModel {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> reportModelError(String title, APIResponse response, {Map<String, String> context = const {}}) async {
|
||||||
|
|
||||||
|
String dataString = response.data?.toString() ?? "null";
|
||||||
|
|
||||||
|
if (dataString.length > 500) {
|
||||||
|
dataString = dataString.substring(0, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add some default context data
|
||||||
|
|
||||||
|
context["url"] = response.url.toString();
|
||||||
|
context["statusCode"] = response.statusCode.toString();
|
||||||
|
context["responseData"] = dataString;
|
||||||
|
context["valid"] = response.isValid().toString();
|
||||||
|
context["error"] = response.error;
|
||||||
|
context["errorDetail"] = response.errorDetail;
|
||||||
|
context["isNull"] = response.data == null ? "true" : "false";
|
||||||
|
context["dataType"] = response.data?.runtimeType.toString() ?? "null";
|
||||||
|
context["model"] = URL;
|
||||||
|
|
||||||
|
await sentryReportMessage(
|
||||||
|
title,
|
||||||
|
context: context,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Delete the instance on the remote server
|
/// Delete the instance on the remote server
|
||||||
/// Returns true if the operation was successful, else false
|
/// Returns true if the operation was successful, else false
|
||||||
Future<bool> delete() async {
|
Future<bool> delete() async {
|
||||||
@ -240,18 +266,10 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
if (!response.isValid() || response.data == null || (response.data is! Map)) {
|
if (!response.isValid() || response.data == null || (response.data is! Map)) {
|
||||||
|
|
||||||
if (response.statusCode > 0) {
|
reportModelError(
|
||||||
await sentryReportMessage(
|
"InvenTreeModel.delete() returned invalid response",
|
||||||
"InvenTreeModel.delete() returned invalid response",
|
response,
|
||||||
context: {
|
);
|
||||||
"url": url,
|
|
||||||
"statusCode": response.statusCode.toString(),
|
|
||||||
"data": response.data?.toString() ?? "null",
|
|
||||||
"error": response.error,
|
|
||||||
"errorDetail": response.errorDetail,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
showServerError(
|
showServerError(
|
||||||
L10().serverError,
|
L10().serverError,
|
||||||
@ -274,20 +292,13 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
if (!response.isValid() || response.data == null || (response.data is! Map)) {
|
if (!response.isValid() || response.data == null || (response.data is! Map)) {
|
||||||
|
|
||||||
// Report error
|
reportModelError(
|
||||||
if (response.statusCode > 0) {
|
"InvenTreeModel.reload() returned invalid response",
|
||||||
await sentryReportMessage(
|
response,
|
||||||
"InvenTreeModel.reload() returned invalid response",
|
context: {
|
||||||
context: {
|
"pk": pk.toString(),
|
||||||
"url": url,
|
}
|
||||||
"statusCode": response.statusCode.toString(),
|
);
|
||||||
"data": response.data?.toString() ?? "null",
|
|
||||||
"valid": response.isValid().toString(),
|
|
||||||
"error": response.error,
|
|
||||||
"errorDetail": response.errorDetail,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
showServerError(
|
showServerError(
|
||||||
L10().serverError,
|
L10().serverError,
|
||||||
@ -347,19 +358,15 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
if (!response.isValid() || response.data == null || response.data is! Map) {
|
if (!response.isValid() || response.data == null || response.data is! Map) {
|
||||||
|
|
||||||
if (response.statusCode > 0) {
|
// Report error
|
||||||
await sentryReportMessage(
|
reportModelError(
|
||||||
"InvenTreeModel.get() returned invalid response",
|
"InvenTreeModel.getModel() returned invalid response",
|
||||||
context: {
|
response,
|
||||||
"url": url,
|
context: {
|
||||||
"statusCode": response.statusCode.toString(),
|
"filters": filters.toString(),
|
||||||
"data": response.data?.toString() ?? "null",
|
"pk": pk,
|
||||||
"valid": response.isValid().toString(),
|
}
|
||||||
"error": response.error,
|
);
|
||||||
"errorDetail": response.errorDetail,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
showServerError(
|
showServerError(
|
||||||
L10().serverError,
|
L10().serverError,
|
||||||
@ -394,26 +401,19 @@ class InvenTreeModel {
|
|||||||
// Invalid response returned from server
|
// Invalid response returned from server
|
||||||
if (!response.isValid() || response.data == null || response.data is! Map) {
|
if (!response.isValid() || response.data == null || response.data is! Map) {
|
||||||
|
|
||||||
if (response.statusCode > 0) {
|
reportModelError(
|
||||||
await sentryReportMessage(
|
"InvenTreeModel.create() returned invalid response",
|
||||||
"InvenTreeModel.create() returned invalid response",
|
response,
|
||||||
context: {
|
context: {
|
||||||
"url": url,
|
"pk": pk.toString(),
|
||||||
"statusCode": response.statusCode.toString(),
|
}
|
||||||
"data": response.data?.toString() ?? "null",
|
);
|
||||||
"valid": response.isValid().toString(),
|
|
||||||
"error": response.error,
|
|
||||||
"errorDetail": response.errorDetail,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
showServerError(
|
showServerError(
|
||||||
L10().serverError,
|
L10().serverError,
|
||||||
L10().errorCreate,
|
L10().errorCreate,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +240,8 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
String username = "";
|
String username = "";
|
||||||
String password = "";
|
String password = "";
|
||||||
|
|
||||||
|
bool _obscured = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -379,10 +381,18 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
labelText: L10().password,
|
labelText: L10().password,
|
||||||
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
||||||
hintText: L10().enterPassword,
|
hintText: L10().enterPassword,
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: _obscured ? FaIcon(FontAwesomeIcons.eye) : FaIcon(FontAwesomeIcons.solidEyeSlash),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscured = !_obscured;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
initialValue: profile?.password ?? "",
|
initialValue: profile?.password ?? "",
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.visiblePassword,
|
||||||
obscureText: true,
|
obscureText: _obscured,
|
||||||
onSaved: (value) {
|
onSaved: (value) {
|
||||||
password = value ?? "";
|
password = value ?? "";
|
||||||
},
|
},
|
||||||
|
@ -180,6 +180,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
*/
|
*/
|
||||||
Future<void> _refreshNotifications() async {
|
Future<void> _refreshNotifications() async {
|
||||||
|
|
||||||
|
if (!InvenTreeAPI().isConnected()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final notifications = await InvenTreeNotification().list();
|
final notifications = await InvenTreeNotification().list();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
|
||||||
import "package:inventree/inventree/sentry.dart";
|
|
||||||
import "package:inventree/widget/snacks.dart";
|
|
||||||
|
|
||||||
import "package:inventree/l10.dart";
|
|
||||||
|
|
||||||
class SubmitFeedbackWidget extends StatefulWidget {
|
|
||||||
|
|
||||||
@override
|
|
||||||
_SubmitFeedbackState createState() => _SubmitFeedbackState();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class _SubmitFeedbackState extends State<SubmitFeedbackWidget> {
|
|
||||||
|
|
||||||
final _formkey = GlobalKey<FormState>();
|
|
||||||
|
|
||||||
String message = "";
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(L10().submitFeedback),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: FaIcon(FontAwesomeIcons.paperPlane),
|
|
||||||
onPressed: () async {
|
|
||||||
if (_formkey.currentState!.validate()) {
|
|
||||||
_formkey.currentState!.save();
|
|
||||||
|
|
||||||
// Upload
|
|
||||||
bool result = await sentryReportMessage(message);
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
showSnackIcon(
|
|
||||||
L10().feedbackSuccess,
|
|
||||||
success: true,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
showSnackIcon(
|
|
||||||
L10().feedbackError,
|
|
||||||
success: false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Form(
|
|
||||||
key: _formkey,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
TextFormField(
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: L10().feedback,
|
|
||||||
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
maxLines: null,
|
|
||||||
keyboardType: TextInputType.multiline,
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.trim().isEmpty) {
|
|
||||||
return L10().valueCannotBeEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
onSaved: (value) {
|
|
||||||
if (value != null) {
|
|
||||||
message = value;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user