Unverified Commit 341e40d0 authored by Dan Jones's avatar Dan Jones
Browse files

fix: correct reference to error status code

+ add catch and retry in poll method
parent b66f89a7
...@@ -82,10 +82,11 @@ class Adapter { ...@@ -82,10 +82,11 @@ class Adapter {
/** /**
* Call the GET /receive endpoint and process the messages with decode * Call the GET /receive endpoint and process the messages with decode
* *
* Returns the response * Returns the response
* @param {boolean} is_retry
* @returns {object} * @returns {object}
*/ */
poll() { poll(is_retry=false) {
let adapterConfig = this.config; let adapterConfig = this.config;
return this.getAuthorizationHeader() return this.getAuthorizationHeader()
.then((headers) => { .then((headers) => {
...@@ -105,7 +106,18 @@ class Adapter { ...@@ -105,7 +106,18 @@ class Adapter {
return response; return response;
}) })
.catch((error) => { .catch((error) => {
return Promise.reject(error); let retry = false;
switch(error.response.status) {
case 403: {
this.credentials = null;
retry = true;
} break;
case 503: {
retry = true;
}
}
if (retry && !is_retry) return this.poll(true);
else return Promise.reject(error);
}); });
} }
...@@ -138,7 +150,7 @@ class Adapter { ...@@ -138,7 +150,7 @@ class Adapter {
}) })
.catch((error) => { .catch((error) => {
let retry = false; let retry = false;
switch(error.response.status_code) { switch(error.response.status) {
case 403: { case 403: {
this.credentials = null; this.credentials = null;
retry = true; retry = true;
...@@ -183,7 +195,7 @@ class Adapter { ...@@ -183,7 +195,7 @@ class Adapter {
}) })
.catch((error) => { .catch((error) => {
let retry = false; let retry = false;
switch(error.response.status_code) { switch(error.response.status) {
case 403: { case 403: {
this.credentials = null; this.credentials = null;
retry = true; retry = true;
......
...@@ -84,10 +84,11 @@ class Adapter { ...@@ -84,10 +84,11 @@ class Adapter {
/** /**
* Call the GET /receive endpoint and process the messages with decode * Call the GET /receive endpoint and process the messages with decode
* *
* Returns the response * Returns the response
* @param {boolean} is_retry
* @returns {object} * @returns {object}
*/ */
poll() { poll(is_retry=false) {
let adapterConfig = this.config; let adapterConfig = this.config;
return this.getAuthorizationHeader() return this.getAuthorizationHeader()
.then((headers) => { .then((headers) => {
...@@ -107,7 +108,18 @@ class Adapter { ...@@ -107,7 +108,18 @@ class Adapter {
return response; return response;
}) })
.catch((error) => { .catch((error) => {
return Promise.reject(error); let retry = false;
switch(error.response.status) {
case 403: {
this.credentials = null;
retry = true;
} break;
case 503: {
retry = true;
}
}
if (retry && !is_retry) return this.poll(true);
else return Promise.reject(error);
}); });
} }
...@@ -140,7 +152,7 @@ class Adapter { ...@@ -140,7 +152,7 @@ class Adapter {
}) })
.catch((error) => { .catch((error) => {
let retry = false; let retry = false;
switch(error.response.status_code) { switch(error.response.status) {
case 403: { case 403: {
this.credentials = null; this.credentials = null;
retry = true; retry = true;
...@@ -185,7 +197,7 @@ class Adapter { ...@@ -185,7 +197,7 @@ class Adapter {
}) })
.catch((error) => { .catch((error) => {
let retry = false; let retry = false;
switch(error.response.status_code) { switch(error.response.status) {
case 403: { case 403: {
this.credentials = null; this.credentials = null;
retry = true; retry = true;
......
...@@ -82,10 +82,11 @@ export class Adapter { ...@@ -82,10 +82,11 @@ export class Adapter {
/** /**
* Call the GET /receive endpoint and process the messages with decode * Call the GET /receive endpoint and process the messages with decode
* *
* Returns the response * Returns the response
* @param {boolean} is_retry
* @returns {object} * @returns {object}
*/ */
poll() { poll(is_retry=false) {
let adapterConfig = this.config; let adapterConfig = this.config;
return this.getAuthorizationHeader() return this.getAuthorizationHeader()
.then((headers) => { .then((headers) => {
...@@ -105,7 +106,18 @@ export class Adapter { ...@@ -105,7 +106,18 @@ export class Adapter {
return response; return response;
}) })
.catch((error) => { .catch((error) => {
return Promise.reject(error); let retry = false;
switch(error.response.status) {
case 403: {
this.credentials = null;
retry = true;
} break;
case 503: {
retry = true;
}
}
if (retry && !is_retry) return this.poll(true);
else return Promise.reject(error);
}); });
} }
...@@ -138,7 +150,7 @@ export class Adapter { ...@@ -138,7 +150,7 @@ export class Adapter {
}) })
.catch((error) => { .catch((error) => {
let retry = false; let retry = false;
switch(error.response.status_code) { switch(error.response.status) {
case 403: { case 403: {
this.credentials = null; this.credentials = null;
retry = true; retry = true;
...@@ -183,7 +195,7 @@ export class Adapter { ...@@ -183,7 +195,7 @@ export class Adapter {
}) })
.catch((error) => { .catch((error) => {
let retry = false; let retry = false;
switch(error.response.status_code) { switch(error.response.status) {
case 403: { case 403: {
this.credentials = null; this.credentials = null;
retry = true; retry = true;
......
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