Improve barcode error handling (#910)

* Improve barcode error handling

Exit early if API call fails

* fix type of default values

* tweak wedge scanner
This commit is contained in:
Oliver authored and GitHub committed 2026-11-09 15:12:58 +11:00
1 parent 08f78763f4
commit 93d47175c8
4 files changed
+28 -8

No files matched your search

+3 -1
View File
@@ -42,7 +42,7 @@ class APIResponse {
this.method = "",
this.statusCode = -1,
this.error = "",
this.data = const {},
this.data = const <String, dynamic>{},
});
int statusCode = -1;
@@ -1816,6 +1816,8 @@ class InvenTreeAPI {
debug("CertificateException at ${request.uri.toString()}:");
debug(error.toString());
showServerError(url, L10().serverCertificateError, error.toString());
response.error = "CertificateException";
response.errorDetail = error.toString();
} on TimeoutException {
showTimeoutError(url);
response.error = "TimeoutException";
+9 -1
View File
@@ -99,8 +99,16 @@ class BarcodeHandler {
Map<String, dynamic> data = response.asMap();
// No usable response (connection failure, timeout, certificate error,
// or a 5xx server error). The API layer has already shown an error
// to the user, and reported any unexpected server errors to sentry.
if (!response.isValid()) {
barcodeFailureTone();
return;
}
// Handle strange response from the server
if (!response.isValid() || !response.isMap()) {
if (!response.isMap()) {
await onBarcodeUnknown({});
showSnackIcon(L10().serverError, success: false);
+10 -4
View File
@@ -50,11 +50,17 @@ class InvenTreeStatusCode {
APIResponse response = await InvenTreeAPI().get(URL);
if (response.statusCode == 200) {
Map<String, dynamic> results = response.data as Map<String, dynamic>;
// Note: the request may be interrupted (e.g. by a disconnect) after the
// status code is received, so the response data must be type-checked
if (response.statusCode == 200 && response.error.isEmpty) {
final dynamic results = response.data;
if (results.containsKey("values")) {
data = results["values"] as Map<String, dynamic>;
if (results is Map<String, dynamic>) {
final dynamic values = results["values"];
if (values is Map<String, dynamic>) {
data = values;
}
}
}
}
+6 -2
View File
@@ -19,7 +19,11 @@ void main() {
// Check debug output
debugContains("scanned: abc");
debugContains("No match for barcode");
debugContains("Server Error");
debugContains("Scanned barcode data: 'abc'");
// No server is available, so the API layer reports the failure,
// and the handler exits early (rather than treating it as an unknown barcode)
debugContains("showServerError");
expect(debugContains("No match for barcode", raiseAssert: false), isFalse);
});
}