From 6d764e32a0ae8c294ab3061380c7e7c17c8c05d8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 10 May 2022 23:37:21 +1000 Subject: [PATCH] Improve barcode error handling --- lib/api.dart | 4 ---- lib/barcode.dart | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 51a414c3..e69f7564 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -332,10 +332,6 @@ class InvenTreeAPI { if (!address.endsWith("/")) { address = address + "/"; } - /* TODO: Better URL validation - * - If not a valid URL, return error - * - If no port supplied, append a default port - */ _BASE_URL = address; diff --git a/lib/barcode.dart b/lib/barcode.dart index af16658a..8781f2d1 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -77,7 +77,7 @@ class BarcodeHandler { body: { "barcode": barcode, }, - expectedStatusCode: 200 + expectedStatusCode: null, // Do not show an error on "unexpected code" ); _controller?.resumeCamera(); @@ -90,7 +90,7 @@ class BarcodeHandler { // We want to know about this one! await sentryReportMessage( - "BarcodeHandler.processBarcode returned strange value", + "BarcodeHandler.processBarcode returned unexpected value", context: { "data": response.data?.toString() ?? "null", "barcode": barcode, @@ -102,7 +102,7 @@ class BarcodeHandler { "overlayText": getOverlayText(context), } ); - } else if (data.containsKey("error")) { + } else if ((response.statusCode >= 400) || data.containsKey("error")) { onBarcodeUnknown(context, data); } else if (data.containsKey("success")) { onBarcodeMatched(context, data);