Bladeren bron

refactored errorMessageParsing to error Util

Abhinav-grd 4 jaren geleden
bovenliggende
commit
a9e6c8a938
2 gewijzigde bestanden met toevoegingen van 22 en 17 verwijderingen
  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 { 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 (
         <Alert
             variant={'danger'}
             style={{ display: bannerErrorCode ? 'block' : 'none' }}
         >
-            {errorMessage}
+            {ErrorBannerMessage(bannerErrorCode)}
         </Alert>
     );
 }

+ 20 - 0
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;
+    }
+}