@@ -224,37 +224,14 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
224
224
225
225
Map <String , Object ?>? startResult;
226
226
227
- MobileScannerErrorCode errorCode = MobileScannerErrorCode .genericError;
228
-
229
227
try {
230
228
startResult = await methodChannel.invokeMapMethod <String , Object ?>(
231
229
'start' ,
232
230
startOptions.toMap (),
233
231
);
234
232
} on PlatformException catch (error) {
235
- // Map the error code to a MobileScannerErrorCode.
236
- // The error code strings should be kept in sync with their native counterparts.
237
- // Any error code that is not mapped will be treated as a generic error.
238
- switch (error.code) {
239
- // In case the scanner was already started, report the right error code.
240
- // If the scanner is already starting,
241
- // this error code is a signal to the controller to just ignore the attempt.
242
- case 'MOBILE_SCANNER_ALREADY_STARTED_ERROR' :
243
- errorCode = MobileScannerErrorCode .controllerAlreadyInitialized;
244
- // In case no cameras are available, using the scanner is not supported.
245
- case 'MOBILE_SCANNER_NO_CAMERA_ERROR' :
246
- errorCode = MobileScannerErrorCode .unsupported;
247
- // This error code should have already been handled
248
- // by the _requestCameraPermission method above,
249
- // but just in case, also handle it here.
250
- case 'MOBILE_SCANNER_CAMERA_PERMISSION_DENIED' :
251
- errorCode = MobileScannerErrorCode .permissionDenied;
252
- default :
253
- break ;
254
- }
255
-
256
233
throw MobileScannerException (
257
- errorCode: errorCode ,
234
+ errorCode: MobileScannerErrorCode . fromPlatformException (error) ,
258
235
errorDetails: MobileScannerErrorDetails (
259
236
code: error.code,
260
237
details: error.details as Object ? ,
0 commit comments