Commit c9d23185 authored by rpereira2's avatar rpereira2

Simplify logic to timeout the validation request

The backoff utility which is already being used, supports timing out.
So use that instead of a manual check for max number of requests.
parent 244966bf
......@@ -9,31 +9,25 @@ import statusCodes from '~/lib/utils/http_status';
import { backOff } from '~/lib/utils/common_utils';
import { queryTypes, formDataValidator } from '../constants';
const MAX_REQUESTS = 4;
const VALIDATION_REQUEST_TIMEOUT = 10000;
const axiosCancelToken = axios.CancelToken;
let cancelTokenSource;
function backOffRequest(makeRequestCallback) {
let requestsCount = 0;
return backOff((next, stop) => {
makeRequestCallback()
.then(resp => {
if (resp.status === statusCodes.OK) {
stop(resp);
} else {
requestsCount += 1;
if (requestsCount < MAX_REQUESTS) {
next();
} else {
stop(resp);
}
}
})
// If the request is cancelled by axios
// then consider it as noop so that its not
// caught by subsequent catches
.catch(thrown => (axios.isCancel(thrown) ? undefined : stop(thrown)));
});
}, VALIDATION_REQUEST_TIMEOUT);
}
export default {
......
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