From 6dd48d0a8d110297878faedbfd3687d6b6f0f191 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 12 Oct 2024 04:43:12 +0300 Subject: [PATCH] added handler for non-existent products --- .../org/foxarmy/barcodescannerforemployees/Requester.kt | 7 ++++++- .../activities/AddAbstractProductActivity.kt | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt index b207fa5..1acace2 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt @@ -15,7 +15,12 @@ class Requester constructor(var siteName: String, var endpoint: String) { val stringRequest = object: StringRequest( Method.POST, url, { resp -> run { - response = resp + response = + if (resp == "") { + "Not found 404" + } else { + resp + } } }, { diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt index fee5ecc..2aea5ed 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt @@ -128,6 +128,12 @@ class AddAbstractProductActivity : AppCompatActivity() { thread { // Я сам в ахуях какой это костыль, пока хз как фиксить, потом придумаю :)) while (requester.response == "") { } + if (requester.response == "Not found 404") { + runOnUiThread { + Toast.makeText(this, "Product not found. Please, try again or type manually", Toast.LENGTH_LONG).show() + } + return@thread + } abstractProduct = Parser().parse(requester.response) requester.response = "" runOnUiThread {