From 951d4d7f4d789a6ca33f28f43ec34262ec55f182 Mon Sep 17 00:00:00 2001 From: Reuben Mangubat Date: Thu, 28 Jan 2021 15:54:51 +0800 Subject: [PATCH] Add exception crash local logging --- .../capacitor/SmartScannerPlugin.kt | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/org/idpass/smartscanner/capacitor/SmartScannerPlugin.kt b/android/src/main/java/org/idpass/smartscanner/capacitor/SmartScannerPlugin.kt index 066a2e6..889aa9d 100644 --- a/android/src/main/java/org/idpass/smartscanner/capacitor/SmartScannerPlugin.kt +++ b/android/src/main/java/org/idpass/smartscanner/capacitor/SmartScannerPlugin.kt @@ -38,23 +38,28 @@ class SmartScannerPlugin : Plugin() { super.handleOnActivityResult(requestCode, resultCode, data) val savedCall = savedCall ?: return if (requestCode == REQUEST_OP_SCANNER) { - Timber.d("Plugin post SmartScannerActivity resultCode %d", resultCode) - if (resultCode == Activity.RESULT_OK) { - val returnedResult = data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT) - Timber.d("Plugin post SmartScannerActivity result %s", returnedResult) - try { - val result = JSONObject(returnedResult) - val ret = JSObject() - ret.put(SmartScannerActivity.SCANNER_RESULT, result) - savedCall.success(ret) - } catch (e: JSONException) { - e.printStackTrace() + try { + Timber.d("Plugin post SmartScannerActivity resultCode %d", resultCode) + if (resultCode == Activity.RESULT_OK) { + val returnedResult = data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT) + Timber.d("Plugin post SmartScannerActivity result %s", returnedResult) + try { + val result = JSONObject(returnedResult) + val ret = JSObject() + ret.put(SmartScannerActivity.SCANNER_RESULT, result) + savedCall.success(ret) + } catch (e: JSONException) { + e.printStackTrace() + } + } else if (resultCode == Activity.RESULT_CANCELED) { + Timber.d("Plugin post SmartScannerActivity RESULT CANCELLED") + savedCall.error("Scanning Cancelled.") + } else { + savedCall.error("Scanning Failed.") } - } else if (resultCode == Activity.RESULT_CANCELED) { - Timber.d("Plugin post SmartScannerActivity RESULT CANCELLED") - savedCall.error("Scanning Cancelled.") - } else { - savedCall.error("Scanning Failed.") + } catch (exception: Exception) { + Timber.e(exception) + exception.printStackTrace() } } else { savedCall.error("Unknown Request Code!")