diff --git a/src/crypto/store/memory-crypto-store.js b/src/crypto/store/memory-crypto-store.js index 2897be81e..f3bab6516 100644 --- a/src/crypto/store/memory-crypto-store.js +++ b/src/crypto/store/memory-crypto-store.js @@ -69,7 +69,7 @@ export default class MemoryCryptoStore { getOrAddOutgoingRoomKeyRequest(request) { const requestBody = request.requestBody; - return Promise.try(() => { + return utils.promiseTry(() => { // first see if we already have an entry for this request. const existing = this._getOutgoingRoomKeyRequest(requestBody); diff --git a/src/store/indexeddb-local-backend.js b/src/store/indexeddb-local-backend.js index b1ddb144d..cbebb6c17 100644 --- a/src/store/indexeddb-local-backend.js +++ b/src/store/indexeddb-local-backend.js @@ -436,7 +436,7 @@ LocalIndexedDBStoreBackend.prototype = { */ _persistSyncData: function(nextBatch, roomsData, groupsData) { logger.log("Persisting sync data up to ", nextBatch); - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["sync"], "readwrite"); const store = txn.objectStore("sync"); store.put({ @@ -456,7 +456,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} Resolves if the events were persisted. */ _persistAccountData: function(accountData) { - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["accountData"], "readwrite"); const store = txn.objectStore("accountData"); for (let i = 0; i < accountData.length; i++) { @@ -475,7 +475,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} Resolves if the users were persisted. */ _persistUserPresenceEvents: function(tuples) { - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["users"], "readwrite"); const store = txn.objectStore("users"); for (const tuple of tuples) { @@ -495,7 +495,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} A list of presence events in their raw form. */ getUserPresenceEvents: function() { - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["users"], "readonly"); const store = txn.objectStore("users"); return selectQuery(store, undefined, (cursor) => { @@ -512,7 +512,7 @@ LocalIndexedDBStoreBackend.prototype = { logger.log( `LocalIndexedDBStoreBackend: loading account data...`, ); - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["accountData"], "readonly"); const store = txn.objectStore("accountData"); return selectQuery(store, undefined, (cursor) => { @@ -534,7 +534,7 @@ LocalIndexedDBStoreBackend.prototype = { logger.log( `LocalIndexedDBStoreBackend: loading sync data...`, ); - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["sync"], "readonly"); const store = txn.objectStore("sync"); return selectQuery(store, undefined, (cursor) => { diff --git a/src/utils.js b/src/utils.js index c24df57aa..2cf2dc509 100644 --- a/src/utils.js +++ b/src/utils.js @@ -737,3 +737,13 @@ module.exports.promiseMapSeries = async (promises, fn) => { await fn(await o); } }; + +module.exports.promiseTry = (fn) => { + return new Promise((resolve, reject) => { + try { + fn().then(resolve, reject); + } catch (e) { + reject(e); + } + }); +};