Amplitude-JavaScript
Amplitude-JavaScript copied to clipboard
This library is using Async Storage but without catching potential errors
Here is the patch file I did to fix the issue
diff --git a/node_modules/amplitude-js/amplitude.native.js b/node_modules/amplitude-js/amplitude.native.js
index 2eff026..bfd2284 100644
--- a/node_modules/amplitude-js/amplitude.native.js
+++ b/node_modules/amplitude-js/amplitude.native.js
@@ -3900,7 +3900,7 @@
*/
- var _saveCookieData = function _saveCookieData(scope) {
+ var _saveCookieData = async function _saveCookieData(scope) {
var cookieData = {
deviceId: scope.options.deviceId,
userId: scope.options.userId,
@@ -3913,7 +3913,9 @@
};
if (AsyncStorage) {
- AsyncStorage.setItem(scope._storageSuffix, JSON.stringify(cookieData));
+ try {
+ await AsyncStorage.setItem(scope._storageSuffix, JSON.stringify(cookieData));
+ } catch (e) {}
}
if (scope._useOldCookie) {
@@ -4064,7 +4066,7 @@
*/
- AmplitudeClient.prototype.saveEvents = function saveEvents() {
+ AmplitudeClient.prototype.saveEvents = async function saveEvents() {
try {
var serializedUnsentEvents = JSON.stringify(this._unsentEvents.map(function (_ref) {
var event = _ref.event;
@@ -4072,7 +4074,7 @@
}));
if (AsyncStorage) {
- AsyncStorage.setItem(this.options.unsentKey + this._storageSuffix, serializedUnsentEvents);
+ await AsyncStorage.setItem(this.options.unsentKey + this._storageSuffix, serializedUnsentEvents);
} else {
this._setInStorage(localStorage$1, this.options.unsentKey, serializedUnsentEvents);
}
@@ -4084,7 +4086,7 @@
}));
if (AsyncStorage) {
- AsyncStorage.setItem(this.options.unsentIdentifyKey + this._storageSuffix, serializedIdentifys);
+ await AsyncStorage.setItem(this.options.unsentIdentifyKey + this._storageSuffix, serializedIdentifys);
} else {
this._setInStorage(localStorage$1, this.options.unsentIdentifyKey, serializedIdentifys);
}