diff --git a/modules/consentManagementGpp.js b/modules/consentManagementGpp.js index 8160ee2378c..f696ce25902 100644 --- a/modules/consentManagementGpp.js +++ b/modules/consentManagementGpp.js @@ -70,13 +70,18 @@ export class GPPClient { * - a promise to GPP data. */ static init(mkCmp = cmpClient) { - if (this.INST == null) { - this.INST = this.ping(mkCmp).catch(e => { - this.INST = null; + let inst = this.INST; + if (!inst) { + let err; + const reset = () => err && (this.INST = null); + inst = this.INST = this.ping(mkCmp).catch(e => { + err = true; + reset(); throw e; }); + reset(); } - return this.INST.then(([client, pingData]) => [ + return inst.then(([client, pingData]) => [ client, client.initialized ? client.refresh() : client.init(pingData) ]); diff --git a/test/spec/modules/consentManagementGpp_spec.js b/test/spec/modules/consentManagementGpp_spec.js index 99d4f94f502..93a876d0233 100644 --- a/test/spec/modules/consentManagementGpp_spec.js +++ b/test/spec/modules/consentManagementGpp_spec.js @@ -290,7 +290,7 @@ describe('consentManagementGpp', function () { }); it('should not re-use errors', (done) => { - cmpResult = Promise.reject(new Error()); + cmpResult = GreedyPromise.reject(new Error()); GPPClient.init(makeCmp).catch(() => { cmpResult = {signalStatus: 'ready'}; return GPPClient.init(makeCmp).then(([client]) => {