function check for breaking error changes
This commit is contained in:
parent
ce8bc629a1
commit
e6049aef1b
|
@ -4,7 +4,7 @@ import { getToken } from 'utils/common/key';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import { UploadFile, UploadURL } from './uploadService';
|
import { UploadFile, UploadURL } from './uploadService';
|
||||||
import { File } from '../fileService';
|
import { File } from '../fileService';
|
||||||
import { CustomError } from 'utils/common/errorUtil';
|
import { CustomError, handleUploadError } from 'utils/common/errorUtil';
|
||||||
import { retryAsyncFunction } from 'utils/network';
|
import { retryAsyncFunction } from 'utils/network';
|
||||||
import { MultipartUploadURLs } from './multiPartUploadService';
|
import { MultipartUploadURLs } from './multiPartUploadService';
|
||||||
|
|
||||||
|
@ -20,10 +20,12 @@ class UploadHttpClient {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await retryAsyncFunction(() =>
|
const response = await retryAsyncFunction(
|
||||||
|
() =>
|
||||||
HTTPService.post(`${ENDPOINT}/files`, uploadFile, null, {
|
HTTPService.post(`${ENDPOINT}/files`, uploadFile, null, {
|
||||||
'X-Auth-Token': token,
|
'X-Auth-Token': token,
|
||||||
})
|
}),
|
||||||
|
handleUploadError
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -2,7 +2,10 @@ import { sleep } from 'utils/common';
|
||||||
|
|
||||||
const retrySleepTimeInMilliSeconds = [2000, 5000, 10000];
|
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 (
|
const retrier = async (
|
||||||
func: () => Promise<any>,
|
func: () => Promise<any>,
|
||||||
attemptNumber: number = 0
|
attemptNumber: number = 0
|
||||||
|
@ -11,6 +14,13 @@ export async function retryAsyncFunction(func: () => Promise<any>) {
|
||||||
const resp = await func();
|
const resp = await func();
|
||||||
return resp;
|
return resp;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (checkForBreakingError) {
|
||||||
|
try {
|
||||||
|
checkForBreakingError(e);
|
||||||
|
} catch (err) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (attemptNumber < retrySleepTimeInMilliSeconds.length) {
|
if (attemptNumber < retrySleepTimeInMilliSeconds.length) {
|
||||||
await sleep(retrySleepTimeInMilliSeconds[attemptNumber]);
|
await sleep(retrySleepTimeInMilliSeconds[attemptNumber]);
|
||||||
await retrier(func, attemptNumber + 1);
|
await retrier(func, attemptNumber + 1);
|
||||||
|
|
Loading…
Reference in a new issue