From a9e6c8a938ca7df32e114f2a86d3bfe707f67300 Mon Sep 17 00:00:00 2001 From: Abhinav-grd Date: Mon, 22 Feb 2021 16:59:39 +0530 Subject: [PATCH] refactored errorMessageParsing to error Util --- src/pages/gallery/components/AlertBanner.tsx | 19 ++----------------- src/utils/common/errorUtil.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/pages/gallery/components/AlertBanner.tsx b/src/pages/gallery/components/AlertBanner.tsx index 38ac81346..eae6dbb89 100644 --- a/src/pages/gallery/components/AlertBanner.tsx +++ b/src/pages/gallery/components/AlertBanner.tsx @@ -1,30 +1,15 @@ import React from 'react'; import { Alert } from 'react-bootstrap'; -import constants from 'utils/strings/constants'; -import {errorCodes} from 'utils/common/errorUtil'; +import { ErrorBannerMessage } from 'utils/common/errorUtil'; export default function AlertBanner({ bannerErrorCode }) { - let errorMessage; - switch (bannerErrorCode) { - case errorCodes.ERR_NO_ACTIVE_SUBSCRIPTION: - errorMessage = constants.SUBSCRIPTION_EXPIRED; - break; - case errorCodes.ERR_STORAGE_LIMIT_EXCEEDED: - errorMessage = constants.STORAGE_QUOTA_EXCEEDED; - break; - case errorCodes.ERR_NO_INTERNET_CONNECTION: - errorMessage = constants.NO_INTERNET_CONNECTION; - break; - default: - errorMessage = `Unknown Error Code - ${bannerErrorCode} Encountered`; - } return ( - {errorMessage} + {ErrorBannerMessage(bannerErrorCode)} ); } diff --git a/src/utils/common/errorUtil.ts b/src/utils/common/errorUtil.ts index 555d0fdae..a09fbfa9a 100644 --- a/src/utils/common/errorUtil.ts +++ b/src/utils/common/errorUtil.ts @@ -1,3 +1,5 @@ +import constants from 'utils/strings/constants'; + export const errorCodes = { ERR_STORAGE_LIMIT_EXCEEDED: '426', ERR_NO_ACTIVE_SUBSCRIPTION: '402', @@ -16,3 +18,21 @@ export function ErrorHandler(error) { return; } } + +export function ErrorBannerMessage(bannerErrorCode) { + let errorMessage; + switch (bannerErrorCode) { + case errorCodes.ERR_NO_ACTIVE_SUBSCRIPTION: + errorMessage = constants.SUBSCRIPTION_EXPIRED; + break; + case errorCodes.ERR_STORAGE_LIMIT_EXCEEDED: + errorMessage = constants.STORAGE_QUOTA_EXCEEDED; + break; + case errorCodes.ERR_NO_INTERNET_CONNECTION: + errorMessage = constants.NO_INTERNET_CONNECTION; + break; + default: + errorMessage = `Unknown Error Code - ${bannerErrorCode} Encountered`; + return errorMessage; + } +}