Skip to content

Commit 9ca27a4

Browse files
authored
fix(core): Exception object was not set on Cap (#5917)
1 parent 7553ede commit 9ca27a4

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

android/capacitor/src/main/assets/native-bridge.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,36 @@
22
/*! Capacitor: https://capacitorjs.com/ - MIT License */
33
/* Generated File. Do not edit. */
44

5-
const nativeBridge = (function (exports) {
5+
var nativeBridge = (function (exports) {
66
'use strict';
77

8+
var ExceptionCode;
9+
(function (ExceptionCode) {
10+
/**
11+
* API is not implemented.
12+
*
13+
* This usually means the API can't be used because it is not implemented for
14+
* the current platform.
15+
*/
16+
ExceptionCode["Unimplemented"] = "UNIMPLEMENTED";
17+
/**
18+
* API is not available.
19+
*
20+
* This means the API can't be used right now because:
21+
* - it is currently missing a prerequisite, such as network connectivity
22+
* - it requires a particular platform or browser version
23+
*/
24+
ExceptionCode["Unavailable"] = "UNAVAILABLE";
25+
})(ExceptionCode || (ExceptionCode = {}));
26+
class CapacitorException extends Error {
27+
constructor(message, code, data) {
28+
super(message);
29+
this.message = message;
30+
this.code = code;
31+
this.data = data;
32+
}
33+
}
34+
835
// For removing exports for iOS/Android, keep let for reassignment
936
// eslint-disable-next-line
1037
let dummy = {};
@@ -468,6 +495,7 @@ const nativeBridge = (function (exports) {
468495
});
469496
};
470497
cap.withPlugin = (_pluginId, _fn) => dummy;
498+
cap.Exception = CapacitorException;
471499
initEvents(win, cap);
472500
initLegacyHandlers(win, cap);
473501
initVendor(win, cap);

core/native-bridge.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
PluginResult,
1111
WindowCapacitor,
1212
} from './src/definitions-internal';
13+
import { CapacitorException } from './src/util';
1314

1415
// For removing exports for iOS/Android, keep let for reassignment
1516
// eslint-disable-next-line
@@ -552,6 +553,8 @@ const initBridge = (w: any): void => {
552553

553554
cap.withPlugin = (_pluginId, _fn) => dummy;
554555

556+
cap.Exception = CapacitorException;
557+
555558
initEvents(win, cap);
556559
initLegacyHandlers(win, cap);
557560
initVendor(win, cap);

ios/Capacitor/Capacitor/assets/native-bridge.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,36 @@
22
/*! Capacitor: https://capacitorjs.com/ - MIT License */
33
/* Generated File. Do not edit. */
44

5-
const nativeBridge = (function (exports) {
5+
var nativeBridge = (function (exports) {
66
'use strict';
77

8+
var ExceptionCode;
9+
(function (ExceptionCode) {
10+
/**
11+
* API is not implemented.
12+
*
13+
* This usually means the API can't be used because it is not implemented for
14+
* the current platform.
15+
*/
16+
ExceptionCode["Unimplemented"] = "UNIMPLEMENTED";
17+
/**
18+
* API is not available.
19+
*
20+
* This means the API can't be used right now because:
21+
* - it is currently missing a prerequisite, such as network connectivity
22+
* - it requires a particular platform or browser version
23+
*/
24+
ExceptionCode["Unavailable"] = "UNAVAILABLE";
25+
})(ExceptionCode || (ExceptionCode = {}));
26+
class CapacitorException extends Error {
27+
constructor(message, code, data) {
28+
super(message);
29+
this.message = message;
30+
this.code = code;
31+
this.data = data;
32+
}
33+
}
34+
835
// For removing exports for iOS/Android, keep let for reassignment
936
// eslint-disable-next-line
1037
let dummy = {};
@@ -468,6 +495,7 @@ const nativeBridge = (function (exports) {
468495
});
469496
};
470497
cap.withPlugin = (_pluginId, _fn) => dummy;
498+
cap.Exception = CapacitorException;
471499
initEvents(win, cap);
472500
initLegacyHandlers(win, cap);
473501
initVendor(win, cap);

0 commit comments

Comments
 (0)