diff --git a/dist/adapter.esm.js b/dist/adapter.esm.js index 1acacf6021bc972b749333ab265f96c0e9d3401f..97b4e82bc6764322c0d9414af25dc2b96ca0c5d0 100644 --- a/dist/adapter.esm.js +++ b/dist/adapter.esm.js @@ -115,9 +115,10 @@ class Adapter { * Messages should be passed through encode before sending * @param {string} topic * @param {string} body + * @param {boolean} is_retry * @returns */ - publish(topic, body) { + publish(topic, body, is_retry=false) { let adapterConfig = this.config; return this.getAuthorizationHeader() .then((headers) => { @@ -136,7 +137,18 @@ class Adapter { return response; }) .catch((error) => { - return Promise.reject(error); + let retry = false; + switch(error.response.status_code) { + case 403: { + this.credentials = null; + retry = true; + } break; + case 503: { + retry = true; + } + } + if (retry && !is_retry) return this.publish(topic, body, true); + else return Promise.reject(error); }); } @@ -148,10 +160,11 @@ class Adapter { * quickly in an emergency scenario. * * Messages should be passed through encode before sending - * @param {*} body + * @param {string} body + * @param {boolean} is_retry * @returns */ - broadcast(body) { + broadcast(body, is_retry=false) { let adapterConfig = this.config; return this.getAuthorizationHeader() .then((headers) => { @@ -169,7 +182,18 @@ class Adapter { return response; }) .catch((error) => { - return Promise.reject(error); + let retry = false; + switch(error.response.status_code) { + case 403: { + this.credentials = null; + retry = true; + } break; + case 503: { + retry = true; + } + } + if (retry && !is_retry) return this.broadcast(body, true); + else return Promise.reject(error); }); } } diff --git a/dist/adapter.js b/dist/adapter.js index c868d51b5627423752f33dc107e47e0a45c1a6f9..57c294f52beb50409046ff1e9f51f0c97ef6fb83 100644 --- a/dist/adapter.js +++ b/dist/adapter.js @@ -117,9 +117,10 @@ class Adapter { * Messages should be passed through encode before sending * @param {string} topic * @param {string} body + * @param {boolean} is_retry * @returns */ - publish(topic, body) { + publish(topic, body, is_retry=false) { let adapterConfig = this.config; return this.getAuthorizationHeader() .then((headers) => { @@ -138,7 +139,18 @@ class Adapter { return response; }) .catch((error) => { - return Promise.reject(error); + let retry = false; + switch(error.response.status_code) { + case 403: { + this.credentials = null; + retry = true; + } break; + case 503: { + retry = true; + } + } + if (retry && !is_retry) return this.publish(topic, body, true); + else return Promise.reject(error); }); } @@ -150,10 +162,11 @@ class Adapter { * quickly in an emergency scenario. * * Messages should be passed through encode before sending - * @param {*} body + * @param {string} body + * @param {boolean} is_retry * @returns */ - broadcast(body) { + broadcast(body, is_retry=false) { let adapterConfig = this.config; return this.getAuthorizationHeader() .then((headers) => { @@ -171,7 +184,18 @@ class Adapter { return response; }) .catch((error) => { - return Promise.reject(error); + let retry = false; + switch(error.response.status_code) { + case 403: { + this.credentials = null; + retry = true; + } break; + case 503: { + retry = true; + } + } + if (retry && !is_retry) return this.broadcast(body, true); + else return Promise.reject(error); }); } } diff --git a/src/adapter/index.js b/src/adapter/index.js index d52101f3481d34171356716313f2cee1417632b2..51ecde7c167bb161b707dd3a176a5ad863ec3511 100644 --- a/src/adapter/index.js +++ b/src/adapter/index.js @@ -115,9 +115,10 @@ export class Adapter { * Messages should be passed through encode before sending * @param {string} topic * @param {string} body + * @param {boolean} is_retry * @returns */ - publish(topic, body) { + publish(topic, body, is_retry=false) { let adapterConfig = this.config; return this.getAuthorizationHeader() .then((headers) => { @@ -136,7 +137,18 @@ export class Adapter { return response; }) .catch((error) => { - return Promise.reject(error); + let retry = false; + switch(error.response.status_code) { + case 403: { + this.credentials = null; + retry = true; + } break; + case 503: { + retry = true; + } + } + if (retry && !is_retry) return this.publish(topic, body, true); + else return Promise.reject(error); }); } @@ -148,10 +160,11 @@ export class Adapter { * quickly in an emergency scenario. * * Messages should be passed through encode before sending - * @param {*} body + * @param {string} body + * @param {boolean} is_retry * @returns */ - broadcast(body) { + broadcast(body, is_retry=false) { let adapterConfig = this.config; return this.getAuthorizationHeader() .then((headers) => { @@ -169,7 +182,18 @@ export class Adapter { return response; }) .catch((error) => { - return Promise.reject(error); + let retry = false; + switch(error.response.status_code) { + case 403: { + this.credentials = null; + retry = true; + } break; + case 503: { + retry = true; + } + } + if (retry && !is_retry) return this.broadcast(body, true); + else return Promise.reject(error); }); } }