Selaa lähdekoodia

added error handler adn grouped errorCode and handler in errorUtil file

Abhinav-grd 4 vuotta sitten
vanhempi
commit
72e9b1cfa2

+ 1 - 1
src/pages/gallery/components/AlertBanner.tsx

@@ -2,7 +2,7 @@ import React from 'react';
 import { Alert } from 'react-bootstrap';
 
 import constants from 'utils/strings/constants';
-import errorCodes from 'utils/common/errorCodes';
+import {errorCodes} from 'utils/common/errorUtil';
 
 export default function AlertBanner({ bannerErrorCode }) {
     let errorMessage;

+ 7 - 10
src/services/uploadService.ts

@@ -5,8 +5,8 @@ import EXIF from 'exif-js';
 import { fileAttribute } from './fileService';
 import { collection, CollectionAndItsLatestFile } from './collectionService';
 import { FILE_TYPE } from 'pages/gallery';
-import errorCodes from 'utils/common/errorCodes';
 import { checkConnectivity } from 'utils/common/utilFunctions';
+import { ErrorHandler } from 'utils/common/errorUtil';
 const CryptoWorker: any =
     typeof window !== 'undefined' &&
     Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' }));
@@ -125,7 +125,11 @@ class UploadService {
 
             progressBarProps.setUploadStage(UPLOAD_STAGES.UPLOADING);
             this.changeProgressBarProps();
-            await this.fetchUploadURLs(token);
+            try {
+                await this.fetchUploadURLs(token);
+            } catch (e) {
+                ErrorHandler(e);
+            }
             const uploadProcesses = [];
             for (let i = 0; i < Math.min(5, this.totalFileCount); i++) {
                 uploadProcesses.push(
@@ -168,14 +172,7 @@ class UploadService {
             this.filesCompleted++;
             this.changeProgressBarProps();
         } catch (e) {
-            if (
-                e.response?.status.toString() ==
-                    errorCodes.ERR_STORAGE_LIMIT_EXCEEDED ||
-                e.response?.status.toString() ==
-                    errorCodes.ERR_NO_ACTIVE_SUBSRICTION
-            ) {
-                throw new Error(e.response.status);
-            }
+            ErrorHandler(e);
             const error = new Error(
                 `Uploading Failed for File - ${rawFile.name}`
             );

+ 0 - 7
src/utils/common/errorCodes.ts

@@ -1,7 +0,0 @@
-const errorCodes = {
-    ERR_STORAGE_LIMIT_EXCEEDED: '426',
-    ERR_NO_ACTIVE_SUBSCRIPTION: '402',
-    ERR_NO_INTERNET_CONNECTION: '1',
-};
-
-export default errorCodes;

+ 19 - 0
src/utils/common/errorUtil.ts

@@ -0,0 +1,19 @@
+export const errorCodes = {
+    ERR_STORAGE_LIMIT_EXCEEDED: '426',
+    ERR_NO_ACTIVE_SUBSCRIPTION: '402',
+    ERR_NO_INTERNET_CONNECTION: '1',
+};
+
+export function ErrorHandler(error) {
+    if (error.res)
+        if (
+            error.response?.status.toString() ==
+                errorCodes.ERR_STORAGE_LIMIT_EXCEEDED ||
+            error.response?.status.toString() ==
+                errorCodes.ERR_NO_ACTIVE_SUBSCRIPTION
+        ) {
+            throw new Error(error.response.status);
+        } else {
+            return;
+        }
+}

+ 1 - 1
src/utils/common/utilFunctions.ts

@@ -1,4 +1,4 @@
-import errorCodes from './errorCodes';
+import errorCodes from './errorUtil';
 
 export function checkConnectivity() {
     if (navigator.onLine) {