use constants for errorCodes

This commit is contained in:
Abhinav-grd 2021-02-18 13:36:50 +05:30
parent 24a0f75930
commit 12368048d0
2 changed files with 17 additions and 5 deletions

View file

@ -1,15 +1,22 @@
import React from 'react';
import { Alert } from 'react-bootstrap';
import {
ERR_STORAGE_LIMIT_EXCEEDED,
ERR_NO_ACTIVE_SUBSRICTION,
} from 'services/uploadService';
import constants from 'utils/strings/constants';
import { ERR_NO_INTERNET_CONNECTION } from './CreateCollection';
export default function AlertBanner({ bannerErrorCode }) {
let errorMessage;
switch (bannerErrorCode) {
case 402:
case ERR_NO_ACTIVE_SUBSRICTION:
errorMessage = constants.SUBSCRIPTION_EXPIRED;
break;
case 426:
case ERR_STORAGE_LIMIT_EXCEEDED:
errorMessage = constants.STORAGE_QUOTA_EXCEEDED;
case ERR_NO_INTERNET_CONNECTION:
errorMessage = constants.NO_INTERNET_CONNECTION;
default:
errorMessage = `Unknown Error Code - ${bannerErrorCode} Encountered`;
}

View file

@ -13,7 +13,8 @@ const ENDPOINT = getEndpoint();
const THUMBNAIL_HEIGHT = 720;
const MAX_ATTEMPTS = 3;
const MIN_THUMBNAIL_SIZE = 50000;
export const ERR_STORAGE_LIMIT_EXCEEDED = 426;
export const ERR_NO_ACTIVE_SUBSRICTION = 402;
interface EncryptionResult {
file: fileAttribute;
key: string;
@ -122,7 +123,7 @@ class UploadService {
progressBarProps.setUploadStage(UPLOAD_STAGES.UPLOADING);
this.changeProgressBarProps();
await this.fetchUploadURLs(token);
const uploadProcesses = [];
for (let i = 0; i < Math.min(5, this.totalFileCount); i++) {
uploadProcesses.push(
@ -138,6 +139,7 @@ class UploadService {
progressBarProps.setUploadStage(UPLOAD_STAGES.FINISH);
progressBarProps.setPercentComplete(100);
} catch (e) {
this.filesToBeUploaded = [];
console.log(e);
throw e;
}
@ -164,7 +166,10 @@ class UploadService {
this.filesCompleted++;
this.changeProgressBarProps();
} catch (e) {
if (e.response?.status == 402 || e.response?.status == 426) {
if (
e.response?.status == ERR_STORAGE_LIMIT_EXCEEDED ||
e.response?.status == ERR_NO_ACTIVE_SUBSRICTION
) {
throw e;
}
const error = new Error(