Unverified Commit b66f89a7 authored by Dan Jones's avatar Dan Jones
Browse files

feat: add retry method to refresh token on 403

At the moment if the backbone token secret changes
the adapter can have a token it thinks is valid but
which can no longer be decrypted by the backbone.

On a 403 error this will trigger a new token grant
and resend the request with the new token.
parent db7232dd
......@@ -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);
});
}
}
......
......@@ -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);
});
}
}
......
......@@ -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);
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment