Skip to content

Commit

Permalink
fix(android): wrap potential native exception
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Feb 29, 2024
1 parent 556d9f2 commit c9bdce4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ui-cameraview/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import {
} from './index.common';
import { File, Utils } from '@nativescript/core';

export function wrapNativeException(ex, errorType = typeof ex) {
if (!(ex instanceof Error) && errorType === 'object') {
const err = new Error(ex.toString());
err['nativeException'] = ex;
//@ts-ignore
err['stackTrace'] = com.tns.NativeScriptException.getStackTraceAsString(ex);
return err;
}
return ex;
}

function getScaleType(scaleType: ScaleType) {
if (typeof scaleType === 'string') {
switch (scaleType) {
Expand Down Expand Up @@ -217,6 +228,8 @@ export class CameraView extends CameraViewBase {
this.photoListeners.push(myListener);
// this.nativeViewProtected.setSavePhotoToDisk(options.savePhotoToDisk !== false);
this.nativeViewProtected.takePhoto(JSON.stringify(options));
}).catch((err) => {
throw wrapNativeException(err);
});
}

Expand Down

0 comments on commit c9bdce4

Please sign in to comment.