From 67f7e8f5ac9892b83fab537a5f00e0de444eaeab Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Tue, 18 Jun 2024 09:36:09 +0200 Subject: [PATCH] add new error class for barcode errors --- lib/src/mobile_scanner_exception.dart | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/src/mobile_scanner_exception.dart b/lib/src/mobile_scanner_exception.dart index cca9bafef..dfbcbe742 100644 --- a/lib/src/mobile_scanner_exception.dart +++ b/lib/src/mobile_scanner_exception.dart @@ -1,6 +1,6 @@ import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; -/// This class represents an exception thrown by the mobile scanner. +/// This class represents an exception thrown by the [MobileScannerController]. class MobileScannerException implements Exception { const MobileScannerException({ required this.errorCode, @@ -16,9 +16,9 @@ class MobileScannerException implements Exception { @override String toString() { if (errorDetails != null && errorDetails?.message != null) { - return "MobileScannerException: code ${errorCode.name}, message: ${errorDetails?.message}"; + return 'MobileScannerException: code ${errorCode.name}, message: ${errorDetails?.message}'; } - return "MobileScannerException: ${errorCode.name}"; + return 'MobileScannerException: ${errorCode.name}'; } } @@ -39,3 +39,22 @@ class MobileScannerErrorDetails { /// The error message from the [PlatformException]. final String? message; } + +/// This class represents an exception thrown by the [MobileScannerController] +/// when a barcode scanning error occurs when processing an input frame. +class MobileScannerBarcodeException implements Exception { + /// Creates a new [MobileScannerBarcodeException] with the given error message. + const MobileScannerBarcodeException(this.message); + + /// The error message of the exception. + final String? message; + + @override + String toString() { + if (message?.isNotEmpty ?? false) { + return 'MobileScannerBarcodeException: $message'; + } + + return 'MobileScannerBarcodeException: Could not detect a barcode in the input image.'; + } +}