added error handler adn grouped errorCode and handler in errorUtil file

This commit is contained in:
Abhinav-grd 2021-02-22 16:50:08 +05:30
parent f7c1e6912a
commit 72e9b1cfa2
5 changed files with 28 additions and 19 deletions

View file

@ -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;

View file

@ -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();
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}`
);

View file

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

View file

@ -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;
}
}

View file

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