From 9ca27a4f8441b368f8bf9d97dda57b1a55ac0e4e Mon Sep 17 00:00:00 2001 From: Mike Summerfeldt <20338451+IT-MikeS@users.noreply.github.com> Date: Thu, 15 Sep 2022 09:59:53 -0400 Subject: [PATCH] fix(core): Exception object was not set on Cap (#5917) --- .../src/main/assets/native-bridge.js | 30 ++++++++++++++++++- core/native-bridge.ts | 3 ++ .../Capacitor/assets/native-bridge.js | 30 ++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/android/capacitor/src/main/assets/native-bridge.js b/android/capacitor/src/main/assets/native-bridge.js index 30e97b22c..269b59ae1 100644 --- a/android/capacitor/src/main/assets/native-bridge.js +++ b/android/capacitor/src/main/assets/native-bridge.js @@ -2,9 +2,36 @@ /*! Capacitor: https://capacitorjs.com/ - MIT License */ /* Generated File. Do not edit. */ -const nativeBridge = (function (exports) { +var nativeBridge = (function (exports) { 'use strict'; + var ExceptionCode; + (function (ExceptionCode) { + /** + * API is not implemented. + * + * This usually means the API can't be used because it is not implemented for + * the current platform. + */ + ExceptionCode["Unimplemented"] = "UNIMPLEMENTED"; + /** + * API is not available. + * + * This means the API can't be used right now because: + * - it is currently missing a prerequisite, such as network connectivity + * - it requires a particular platform or browser version + */ + ExceptionCode["Unavailable"] = "UNAVAILABLE"; + })(ExceptionCode || (ExceptionCode = {})); + class CapacitorException extends Error { + constructor(message, code, data) { + super(message); + this.message = message; + this.code = code; + this.data = data; + } + } + // For removing exports for iOS/Android, keep let for reassignment // eslint-disable-next-line let dummy = {}; @@ -468,6 +495,7 @@ const nativeBridge = (function (exports) { }); }; cap.withPlugin = (_pluginId, _fn) => dummy; + cap.Exception = CapacitorException; initEvents(win, cap); initLegacyHandlers(win, cap); initVendor(win, cap); diff --git a/core/native-bridge.ts b/core/native-bridge.ts index e13628fe4..10b4ffd56 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -10,6 +10,7 @@ import type { PluginResult, WindowCapacitor, } from './src/definitions-internal'; +import { CapacitorException } from './src/util'; // For removing exports for iOS/Android, keep let for reassignment // eslint-disable-next-line @@ -552,6 +553,8 @@ const initBridge = (w: any): void => { cap.withPlugin = (_pluginId, _fn) => dummy; + cap.Exception = CapacitorException; + initEvents(win, cap); initLegacyHandlers(win, cap); initVendor(win, cap); diff --git a/ios/Capacitor/Capacitor/assets/native-bridge.js b/ios/Capacitor/Capacitor/assets/native-bridge.js index 30e97b22c..269b59ae1 100644 --- a/ios/Capacitor/Capacitor/assets/native-bridge.js +++ b/ios/Capacitor/Capacitor/assets/native-bridge.js @@ -2,9 +2,36 @@ /*! Capacitor: https://capacitorjs.com/ - MIT License */ /* Generated File. Do not edit. */ -const nativeBridge = (function (exports) { +var nativeBridge = (function (exports) { 'use strict'; + var ExceptionCode; + (function (ExceptionCode) { + /** + * API is not implemented. + * + * This usually means the API can't be used because it is not implemented for + * the current platform. + */ + ExceptionCode["Unimplemented"] = "UNIMPLEMENTED"; + /** + * API is not available. + * + * This means the API can't be used right now because: + * - it is currently missing a prerequisite, such as network connectivity + * - it requires a particular platform or browser version + */ + ExceptionCode["Unavailable"] = "UNAVAILABLE"; + })(ExceptionCode || (ExceptionCode = {})); + class CapacitorException extends Error { + constructor(message, code, data) { + super(message); + this.message = message; + this.code = code; + this.data = data; + } + } + // For removing exports for iOS/Android, keep let for reassignment // eslint-disable-next-line let dummy = {}; @@ -468,6 +495,7 @@ const nativeBridge = (function (exports) { }); }; cap.withPlugin = (_pluginId, _fn) => dummy; + cap.Exception = CapacitorException; initEvents(win, cap); initLegacyHandlers(win, cap); initVendor(win, cap);