Navaron Bracke

handle errors from start() in callback

... ... @@ -165,7 +165,6 @@ class MobileScannerHandler(
val detectionSpeed: DetectionSpeed = DetectionSpeed.values().first { it.intValue == speed}
try {
mobileScanner!!.start(
barcodeScannerOptions,
returnImage,
... ... @@ -183,41 +182,44 @@ class MobileScannerHandler(
))
}
},
timeout.toLong(),
cameraResolution,
)
} catch (e: AlreadyStarted) {
mobileScannerErrorCallback = {
Handler(Looper.getMainLooper()).post {
when (it) {
is AlreadyStarted -> {
result.error(
"MobileScanner",
"Called start() while already started",
null
)
} catch (e: NoCamera) {
result.error(
"MobileScanner",
"No camera found or failed to open camera!",
null
)
} catch (e: TorchError) {
}
is CameraError -> {
result.error(
"MobileScanner",
"Error occurred when setting torch!",
"Error occurred when setting up camera!",
null
)
} catch (e: CameraError) {
}
is NoCamera -> {
result.error(
"MobileScanner",
"Error occurred when setting up camera!",
"No camera found or failed to open camera!",
null
)
} catch (e: Exception) {
}
else -> {
result.error(
"MobileScanner",
"Unknown error occurred..",
"Unknown error occurred.",
null
)
}
}
}
},
timeout.toLong(),
cameraResolution,
)
}
private fun stop(result: MethodChannel.Result) {
try {
... ...