浏览代码

refactored errorMessageParsing to error Util

Abhinav-grd 4 年之前
父节点
当前提交
a9e6c8a938
共有 2 个文件被更改,包括 22 次插入17 次删除
  1. 2 17
      src/pages/gallery/components/AlertBanner.tsx
  2. 20 0
      src/utils/common/errorUtil.ts

+ 2 - 17
src/pages/gallery/components/AlertBanner.tsx

@@ -1,30 +1,15 @@
 import React from 'react';
 import React from 'react';
 import { Alert } from 'react-bootstrap';
 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 }) {
 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 (
     return (
         <Alert
         <Alert
             variant={'danger'}
             variant={'danger'}
             style={{ display: bannerErrorCode ? 'block' : 'none' }}
             style={{ display: bannerErrorCode ? 'block' : 'none' }}
         >
         >
-            {errorMessage}
+            {ErrorBannerMessage(bannerErrorCode)}
         </Alert>
         </Alert>
     );
     );
 }
 }

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

@@ -1,3 +1,5 @@
+import constants from 'utils/strings/constants';
+
 export const errorCodes = {
 export const errorCodes = {
     ERR_STORAGE_LIMIT_EXCEEDED: '426',
     ERR_STORAGE_LIMIT_EXCEEDED: '426',
     ERR_NO_ACTIVE_SUBSCRIPTION: '402',
     ERR_NO_ACTIVE_SUBSCRIPTION: '402',
@@ -16,3 +18,21 @@ export function ErrorHandler(error) {
         return;
         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;
+    }
+}