function check for breaking error changes

This commit is contained in:
Abhinav-grd 2021-08-29 11:48:53 +05:30
parent ce8bc629a1
commit e6049aef1b
2 changed files with 18 additions and 6 deletions

View file

@ -4,7 +4,7 @@ import { getToken } from 'utils/common/key';
import { logError } from 'utils/sentry';
import { UploadFile, UploadURL } from './uploadService';
import { File } from '../fileService';
import { CustomError } from 'utils/common/errorUtil';
import { CustomError, handleUploadError } from 'utils/common/errorUtil';
import { retryAsyncFunction } from 'utils/network';
import { MultipartUploadURLs } from './multiPartUploadService';
@ -20,10 +20,12 @@ class UploadHttpClient {
if (!token) {
return;
}
const response = await retryAsyncFunction(() =>
const response = await retryAsyncFunction(
() =>
HTTPService.post(`${ENDPOINT}/files`, uploadFile, null, {
'X-Auth-Token': token,
})
}),
handleUploadError
);
return response.data;
} catch (e) {

View file

@ -2,7 +2,10 @@ import { sleep } from 'utils/common';
const retrySleepTimeInMilliSeconds = [2000, 5000, 10000];
export async function retryAsyncFunction(func: () => Promise<any>) {
export async function retryAsyncFunction(
func: () => Promise<any>,
checkForBreakingError?: (error) => void
) {
const retrier = async (
func: () => Promise<any>,
attemptNumber: number = 0
@ -11,6 +14,13 @@ export async function retryAsyncFunction(func: () => Promise<any>) {
const resp = await func();
return resp;
} catch (e) {
if (checkForBreakingError) {
try {
checkForBreakingError(e);
} catch (err) {
throw e;
}
}
if (attemptNumber < retrySleepTimeInMilliSeconds.length) {
await sleep(retrySleepTimeInMilliSeconds[attemptNumber]);
await retrier(func, attemptNumber + 1);