From ce8bc629a1b92d2c881b11894482bffadfcbe862 Mon Sep 17 00:00:00 2001 From: Abhinav-grd Date: Sun, 29 Aug 2021 11:47:37 +0530 Subject: [PATCH] renamed parseError and handleError to upload specfic names --- src/services/upload/uploadService.ts | 7 ++----- src/services/upload/uploader.ts | 4 ++-- src/utils/common/errorUtil.ts | 7 ++++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/services/upload/uploadService.ts b/src/services/upload/uploadService.ts index f86610cca..cab101f8f 100644 --- a/src/services/upload/uploadService.ts +++ b/src/services/upload/uploadService.ts @@ -17,7 +17,7 @@ import { encryptFiledata } from './encryptionService'; import { ENCRYPTION_CHUNK_SIZE } from 'types'; import { uploadStreamUsingMultipart } from './multiPartUploadService'; import UIService from './uiService'; -import { parseError } from 'utils/common/errorUtil'; +import { handleUploadError } from 'utils/common/errorUtil'; import { MetadataMap } from './uploadManager'; import { fileIsHEIC } from 'utils/file'; @@ -258,10 +258,7 @@ class UploadService { await this.fetchUploadURLs(); // checking for any subscription related errors } catch (e) { - const { parsedError, parsed } = parseError(e); - if (parsed) { - throw parsedError; - } + handleUploadError(e); } } diff --git a/src/services/upload/uploader.ts b/src/services/upload/uploader.ts index c94c0156a..4bfc6c482 100644 --- a/src/services/upload/uploader.ts +++ b/src/services/upload/uploader.ts @@ -1,6 +1,6 @@ import { File, FILE_TYPE } from 'services/fileService'; import { sleep } from 'utils/common'; -import { handleError, CustomError } from 'utils/common/errorUtil'; +import { handleUploadError, CustomError } from 'utils/common/errorUtil'; import { decryptFile } from 'utils/file'; import { logError } from 'utils/sentry'; import { fileAlreadyInCollection } from 'utils/upload'; @@ -98,7 +98,7 @@ export default async function uploader( const fileFormat = fileTypeInfo.exactType ?? rawFile.name.split('.')[-1]; logError(e, 'file upload failed', { fileFormat }); - handleError(e); + handleUploadError(e); switch (e.message) { case CustomError.ETAG_MISSING: UIService.setFileProgress( diff --git a/src/utils/common/errorUtil.ts b/src/utils/common/errorUtil.ts index 64f6b0e7c..674105c16 100644 --- a/src/utils/common/errorUtil.ts +++ b/src/utils/common/errorUtil.ts @@ -1,3 +1,4 @@ +import { AxiosResponse } from 'axios'; import constants from 'utils/strings/constants'; export const ServerErrorCodes = { @@ -19,7 +20,7 @@ export const CustomError = { UNSUPPORTED_FILE_FORMAT: 'unsupported file formats', }; -export function parseError(error) { +function parseUploadError(error: AxiosResponse) { let parsedMessage = null; if (error?.status) { const errorCode = error.status.toString(); @@ -48,8 +49,8 @@ export function parseError(error) { } } -export function handleError(error) { - const { parsedError, parsed } = parseError(error); +export function handleUploadError(error: AxiosResponse) { + const { parsedError, parsed } = parseUploadError(error); if (parsed) { throw parsedError; } else {