From 64e6f407793fa2ab1e8683111f23b4dcdde99641 Mon Sep 17 00:00:00 2001 From: kahoona77 Date: Tue, 9 May 2017 14:10:38 +0200 Subject: [PATCH] catch unhandled rejection with installation-handling (#3795) --- src/RestWrite.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/RestWrite.js b/src/RestWrite.js index 5ad94544..da9610e8 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -793,7 +793,15 @@ RestWrite.prototype.handleInstallation = function() { if (this.data.appIdentifier) { delQuery['appIdentifier'] = this.data.appIdentifier; } - this.config.database.destroy('_Installation', delQuery); + this.config.database.destroy('_Installation', delQuery) + .catch(err => { + if (err.code == Parse.Error.OBJECT_NOT_FOUND) { + // no deletions were made. Can be ignored. + return; + } + // rethrow the error + throw err; + }); return; } } else { @@ -806,6 +814,14 @@ RestWrite.prototype.handleInstallation = function() { return this.config.database.destroy('_Installation', delQuery) .then(() => { return deviceTokenMatches[0]['objectId']; + }) + .catch(err => { + if (err.code == Parse.Error.OBJECT_NOT_FOUND) { + // no deletions were made. Can be ignored + return; + } + // rethrow the error + throw err; }); } else { if (this.data.deviceToken && @@ -835,7 +851,15 @@ RestWrite.prototype.handleInstallation = function() { if (this.data.appIdentifier) { delQuery['appIdentifier'] = this.data.appIdentifier; } - this.config.database.destroy('_Installation', delQuery); + this.config.database.destroy('_Installation', delQuery) + .catch(err => { + if (err.code == Parse.Error.OBJECT_NOT_FOUND) { + // no deletions were made. Can be ignored. + return; + } + // rethrow the error + throw err; + }); } // In non-merge scenarios, just return the installation match id return idMatch.objectId;