Navaron Bracke

add MobileScannerBarcodeException & fix error to string implementation

1 import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; 1 import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart';
2 2
3 -/// This class represents an exception thrown by the mobile scanner. 3 +/// This class represents an exception thrown by the [MobileScannerController].
4 class MobileScannerException implements Exception { 4 class MobileScannerException implements Exception {
5 const MobileScannerException({ 5 const MobileScannerException({
6 required this.errorCode, 6 required this.errorCode,
@@ -16,9 +16,9 @@ class MobileScannerException implements Exception { @@ -16,9 +16,9 @@ class MobileScannerException implements Exception {
16 @override 16 @override
17 String toString() { 17 String toString() {
18 if (errorDetails != null && errorDetails?.message != null) { 18 if (errorDetails != null && errorDetails?.message != null) {
19 - return "MobileScannerException: code ${errorCode.name}, message: ${errorDetails?.message}"; 19 + return 'MobileScannerException(${errorCode.name}, ${errorDetails?.message})';
20 } 20 }
21 - return "MobileScannerException: ${errorCode.name}"; 21 + return 'MobileScannerException(${errorCode.name})';
22 } 22 }
23 } 23 }
24 24
@@ -46,3 +46,22 @@ class MobileScannerErrorDetails { @@ -46,3 +46,22 @@ class MobileScannerErrorDetails {
46 /// This exception type is only used internally, 46 /// This exception type is only used internally,
47 /// and is not part of the public API. 47 /// and is not part of the public API.
48 class PermissionRequestPendingException implements Exception {} 48 class PermissionRequestPendingException implements Exception {}
  49 +
  50 +/// This class represents an exception thrown by the [MobileScannerController]
  51 +/// when a barcode scanning error occurs when processing an input frame.
  52 +class MobileScannerBarcodeException implements Exception {
  53 + /// Creates a new [MobileScannerBarcodeException] with the given error message.
  54 + const MobileScannerBarcodeException(this.message);
  55 +
  56 + /// The error message of the exception.
  57 + final String? message;
  58 +
  59 + @override
  60 + String toString() {
  61 + if (message?.isNotEmpty ?? false) {
  62 + return 'MobileScannerBarcodeException($message)';
  63 + }
  64 +
  65 + return 'MobileScannerBarcodeException(Could not detect a barcode in the input image.)';
  66 + }
  67 +}