Showing
4 changed files
with
101 additions
and
1 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/objects/MobileScannerErrorCodes.kt
0 → 100644
| 1 | +package dev.steenbakker.mobile_scanner.objects | ||
| 2 | + | ||
| 3 | +class MobileScannerErrorCodes { | ||
| 4 | + companion object { | ||
| 5 | + const val ALREADY_STARTED_ERROR = "MOBILE_SCANNER_ALREADY_STARTED_ERROR" | ||
| 6 | + const val ALREADY_STARTED_ERROR_MESSAGE = "The scanner was already started." | ||
| 7 | + // The error code 'BARCODE_ERROR' does not have an error message, | ||
| 8 | + // because it uses the error message from the underlying error. | ||
| 9 | + const val BARCODE_ERROR = "MOBILE_SCANNER_BARCODE_ERROR" | ||
| 10 | + // The error code 'CAMERA_ACCESS_DENIED' does not have an error message, | ||
| 11 | + // because it is used for a boolean result. | ||
| 12 | + const val CAMERA_ACCESS_DENIED = "MOBILE_SCANNER_CAMERA_PERMISSION_DENIED" | ||
| 13 | + const val CAMERA_ERROR = "MOBILE_SCANNER_CAMERA_ERROR" | ||
| 14 | + const val CAMERA_ERROR_MESSAGE = "An error occurred when opening the camera." | ||
| 15 | + const val CAMERA_PERMISSIONS_REQUEST_ONGOING = "MOBILE_SCANNER_CAMERA_PERMISSION_REQUEST_PENDING" | ||
| 16 | + const val CAMERA_PERMISSIONS_REQUEST_ONGOING_MESSAGE = "Another request is ongoing and multiple requests cannot be handled at once." | ||
| 17 | + const val GENERIC_ERROR = "MOBILE_SCANNER_GENERIC_ERROR" | ||
| 18 | + const val GENERIC_ERROR_MESSAGE = "An unknown error occurred." | ||
| 19 | + const val INVALID_ZOOM_SCALE_ERROR_MESSAGE = "The zoom scale should be between 0 and 1 (both inclusive)" | ||
| 20 | + const val NO_CAMERA_ERROR = "MOBILE_SCANNER_NO_CAMERA_ERROR" | ||
| 21 | + const val NO_CAMERA_ERROR_MESSAGE = "No cameras available." | ||
| 22 | + const val SET_SCALE_WHEN_STOPPED_ERROR = "MOBILE_SCANNER_SET_SCALE_WHEN_STOPPED_ERROR" | ||
| 23 | + const val SET_SCALE_WHEN_STOPPED_ERROR_MESSAGE = "The zoom scale cannot be changed when the camera is stopped." | ||
| 24 | + } | ||
| 25 | +} |
ios/Classes/MobileScannerErrorCodes.swift
0 → 100644
| 1 | +// | ||
| 2 | +// MobileScannerErrorCodes.swift | ||
| 3 | +// mobile_scanner | ||
| 4 | +// | ||
| 5 | +// Created by Navaron Bracke on 28/05/2024. | ||
| 6 | +// | ||
| 7 | + | ||
| 8 | +import Foundation | ||
| 9 | + | ||
| 10 | +/// This struct defines the error codes and error messages for MobileScanner errors. | ||
| 11 | +/// | ||
| 12 | +/// These are used by `FlutterError` as error code and error message. | ||
| 13 | +/// | ||
| 14 | +/// This struct should not be confused with `MobileScannerError`, | ||
| 15 | +/// which is an implementation detail for the iOS implementation. | ||
| 16 | +struct MobileScannerErrorCodes { | ||
| 17 | + static let ALREADY_STARTED_ERROR = "MOBILE_SCANNER_ALREADY_STARTED_ERROR" | ||
| 18 | + static let ALREADY_STARTED_ERROR_MESSAGE = "The scanner was already started." | ||
| 19 | + // The error code 'BARCODE_ERROR' does not have an error message, | ||
| 20 | + // because it uses the error message from the undelying error. | ||
| 21 | + static let BARCODE_ERROR = "MOBILE_SCANNER_BARCODE_ERROR" | ||
| 22 | + // The error code 'CAMERA_ERROR' does not have an error message, | ||
| 23 | + // because it uses the error message from the underlying error. | ||
| 24 | + static let CAMERA_ERROR = "MOBILE_SCANNER_CAMERA_ERROR" | ||
| 25 | + static let GENERIC_ERROR = "MOBILE_SCANNER_GENERIC_ERROR" | ||
| 26 | + static let GENERIC_ERROR_MESSAGE = "An unknown error occurred." | ||
| 27 | + // This message is used with the 'GENERIC_ERROR' error code. | ||
| 28 | + static let INVALID_ZOOM_SCALE_ERROR_MESSAGE = "The zoom scale should be between 0 and 1 (both inclusive)" | ||
| 29 | + static let NO_CAMERA_ERROR = "MOBILE_SCANNER_NO_CAMERA_ERROR" | ||
| 30 | + static let NO_CAMERA_ERROR_MESSAGE = "No cameras available." | ||
| 31 | + static let SET_SCALE_WHEN_STOPPED_ERROR = "MOBILE_SCANNER_SET_SCALE_WHEN_STOPPED_ERROR" | ||
| 32 | + static let SET_SCALE_WHEN_STOPPED_ERROR_MESSAGE = "The zoom scale cannot be changed when the camera is stopped." | ||
| 33 | +} |
| 1 | +import 'package:flutter/services.dart'; | ||
| 1 | import 'package:mobile_scanner/src/mobile_scanner_controller.dart'; | 2 | import 'package:mobile_scanner/src/mobile_scanner_controller.dart'; |
| 2 | 3 | ||
| 3 | /// This enum defines the different error codes for the mobile scanner. | 4 | /// This enum defines the different error codes for the mobile scanner. |
| @@ -24,5 +25,25 @@ enum MobileScannerErrorCode { | @@ -24,5 +25,25 @@ enum MobileScannerErrorCode { | ||
| 24 | permissionDenied, | 25 | permissionDenied, |
| 25 | 26 | ||
| 26 | /// Scanning is unsupported on the current device. | 27 | /// Scanning is unsupported on the current device. |
| 27 | - unsupported, | 28 | + unsupported; |
| 29 | + | ||
| 30 | + /// Convert the given [PlatformException.code] to a [MobileScannerErrorCode]. | ||
| 31 | + factory MobileScannerErrorCode.fromPlatformException( | ||
| 32 | + PlatformException exception, | ||
| 33 | + ) { | ||
| 34 | + // The following error code mapping should be kept in sync with their native counterparts. | ||
| 35 | + // These are located in `MobileScannerErrorCodes.kt` and `MobileScannerErrorCodes.swift`. | ||
| 36 | + return switch (exception.code) { | ||
| 37 | + // In case the scanner was already started, report the right error code. | ||
| 38 | + // If the scanner is already starting, | ||
| 39 | + // this error code is a signal to the controller to just ignore the attempt. | ||
| 40 | + 'MOBILE_SCANNER_ALREADY_STARTED_ERROR' => | ||
| 41 | + MobileScannerErrorCode.controllerAlreadyInitialized, | ||
| 42 | + // In case no cameras are available, using the scanner is not supported. | ||
| 43 | + 'MOBILE_SCANNER_NO_CAMERA_ERROR' => MobileScannerErrorCode.unsupported, | ||
| 44 | + 'MOBILE_SCANNER_CAMERA_PERMISSION_DENIED' => | ||
| 45 | + MobileScannerErrorCode.permissionDenied, | ||
| 46 | + _ => MobileScannerErrorCode.genericError, | ||
| 47 | + }; | ||
| 48 | + } | ||
| 28 | } | 49 | } |
| 1 | +// | ||
| 2 | +// MobileScannerErrorCodes.swift | ||
| 3 | +// mobile_scanner | ||
| 4 | +// | ||
| 5 | +// Created by Navaron Bracke on 27/05/2024. | ||
| 6 | +// | ||
| 7 | + | ||
| 8 | +import Foundation | ||
| 9 | + | ||
| 10 | +struct MobileScannerErrorCodes { | ||
| 11 | + static let ALREADY_STARTED_ERROR = "MOBILE_SCANNER_ALREADY_STARTED_ERROR" | ||
| 12 | + static let ALREADY_STARTED_ERROR_MESSAGE = "The scanner was already started." | ||
| 13 | + // The error code 'BARCODE_ERROR' does not have an error message, | ||
| 14 | + // because it uses the error message from the undelying error. | ||
| 15 | + static let BARCODE_ERROR = "MOBILE_SCANNER_BARCODE_ERROR" | ||
| 16 | + // The error code 'CAMERA_ERROR' does not have an error message, | ||
| 17 | + // because it uses the error message from the underlying error. | ||
| 18 | + static let CAMERA_ERROR = "MOBILE_SCANNER_CAMERA_ERROR" | ||
| 19 | + static let NO_CAMERA_ERROR = "MOBILE_SCANNER_NO_CAMERA_ERROR" | ||
| 20 | + static let NO_CAMERA_ERROR_MESSAGE = "No cameras available." | ||
| 21 | +} |
-
Please register or login to post a comment