Adds a retry logic when fetching conference numbers and pin.

This commit is contained in:
damencho 2019-08-13 16:34:44 +03:00 committed by Дамян Минков
parent 75ab890707
commit 21fb225726
3 changed files with 29 additions and 6 deletions

View File

@ -1,15 +1,25 @@
import { timeoutPromise } from './timeoutPromise';
const logger = require('jitsi-meet-logger').getLogger(__filename);
/**
* The number of milliseconds before deciding that we need retry a fetch request.
*
* @type {number}
*/
const RETRY_TIMEOUT = 3000;
/**
* Wrapper around fetch GET requests to handle json-ifying the response
* and logging errors.
*
* @param {string} url - The URL to perform a GET against.
* @param {?boolean} retry - Whether the request will be retried after short timeout.
* @returns {Promise<Object>} The response body, in JSON format, will be
* through the Promise.
*/
export function doGetJSON(url) {
return fetch(url)
export function doGetJSON(url, retry) {
const fetchPromise = fetch(url)
.then(response => {
const jsonify = response.json();
@ -25,4 +35,17 @@ export function doGetJSON(url) {
return Promise.reject(error);
});
if (retry) {
return timeoutPromise(fetchPromise, RETRY_TIMEOUT)
.catch(response => {
if (response.status >= 400 && response.status < 500) {
return Promise.reject(response);
}
return timeoutPromise(fetchPromise, RETRY_TIMEOUT);
});
}
return fetchPromise;
}

View File

@ -177,7 +177,7 @@ class DialInSummary extends Component<Props, State> {
return Promise.resolve();
}
return doGetJSON(`${dialInConfCodeUrl}?conference=${room}@${mucURL}`)
return doGetJSON(`${dialInConfCodeUrl}?conference=${room}@${mucURL}`, true)
.catch(() => Promise.reject(this.props.t('info.genericError')));
}
@ -204,7 +204,7 @@ class DialInSummary extends Component<Props, State> {
URLSuffix = `?conference=${room}@${mucURL}`;
}
return doGetJSON(`${dialInNumbersUrl}${URLSuffix}`)
return doGetJSON(`${dialInNumbersUrl}${URLSuffix}`, true)
.catch(() => Promise.reject(this.props.t('info.genericError')));
}

View File

@ -48,7 +48,7 @@ export function getDialInConferenceID(
const conferenceIDURL = `${baseUrl}?conference=${roomName}@${mucURL}`;
return doGetJSON(conferenceIDURL);
return doGetJSON(conferenceIDURL, true);
}
/**
@ -71,7 +71,7 @@ export function getDialInNumbers(
const fullUrl = `${url}?conference=${roomName}@${mucURL}`;
return doGetJSON(fullUrl);
return doGetJSON(fullUrl, true);
}
/**