From 4f1abf7018d1e29efb2cd89b6562346ad0ce04a6 Mon Sep 17 00:00:00 2001 From: Prajjaval Verma Date: Mon, 13 Jan 2025 19:49:39 +0530 Subject: [PATCH] NTP-27695 | RN Pages Network Error (#14517) --- .../error-screen/QuoteOfferErrorScreen.tsx | 1 + App/common/actions/GenericAction.ts | 1 + App/common/constants/StatusCodeConstant.ts | 3 ++ App/common/screen/ScreenActionHandler.tsx | 13 ++++-- App/common/utilities/ErrorUtils.ts | 41 +++++++++++++++---- .../widget-actions/WidgetActionHandler.ts | 2 +- 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/App/Container/Navi-Insurance/screen/quote-offer-screen/error-screen/QuoteOfferErrorScreen.tsx b/App/Container/Navi-Insurance/screen/quote-offer-screen/error-screen/QuoteOfferErrorScreen.tsx index 211fd04fa7..5edcf4596e 100644 --- a/App/Container/Navi-Insurance/screen/quote-offer-screen/error-screen/QuoteOfferErrorScreen.tsx +++ b/App/Container/Navi-Insurance/screen/quote-offer-screen/error-screen/QuoteOfferErrorScreen.tsx @@ -29,6 +29,7 @@ const QuoteOfferErrorScreen = ({ }; const errorResponse = getErrorResponseFromStatusCode( errorMetaData?.errorStatusCode, + errorMetaData?.errorAxiosCode, ); return ( diff --git a/App/common/actions/GenericAction.ts b/App/common/actions/GenericAction.ts index e07862fa2a..f22af6f72b 100644 --- a/App/common/actions/GenericAction.ts +++ b/App/common/actions/GenericAction.ts @@ -16,6 +16,7 @@ export interface GenericActionPayload { export interface ErrorMetaData extends GenericActionPayload { errorStatusCode?: number; + errorAxiosCode?: string; } export interface ActionMetaData { diff --git a/App/common/constants/StatusCodeConstant.ts b/App/common/constants/StatusCodeConstant.ts index 3c022e2700..9c00fd1e6d 100644 --- a/App/common/constants/StatusCodeConstant.ts +++ b/App/common/constants/StatusCodeConstant.ts @@ -9,3 +9,6 @@ export const STATUS_CODE_TIMEOUT = 408; export const STATUS_CODE_CONFLICT = 409; export const STATUS_CODE_GATEWAY_TIMEOUT = 504; export const STATUS_CODE_TOO_MANY_REQUESTS = 429; + +export const AXIOS_CODE_NETWORK = "ERR_NETWORK"; +export const AXIOS_CODE_CANCELED = "ERR_CANCELED"; diff --git a/App/common/screen/ScreenActionHandler.tsx b/App/common/screen/ScreenActionHandler.tsx index 1c0519a047..e679c89bce 100644 --- a/App/common/screen/ScreenActionHandler.tsx +++ b/App/common/screen/ScreenActionHandler.tsx @@ -11,6 +11,8 @@ import { } from "../../Container/Navi-Insurance/network"; import { ActionMetaData, BaseActionTypes } from "../actions/GenericAction"; import { + AXIOS_CODE_CANCELED, + AXIOS_CODE_NETWORK, AnalyticsEventNameConstants, AnalyticsModuleNameConstant, EVENT_NAMES, @@ -112,12 +114,16 @@ export const handleErrorData = ( moduleName: AnalyticsModuleNameConstant.GI, flowName, methodName: methodName, - globalErrorType: getErrorTypeFromStatusCode(error.statusCode || -1), + globalErrorType: getErrorTypeFromStatusCode(error.statusCode), isAppDowntimeEvent: false, errorCode: error.axiosCode, - errorTitle: getErrorTitleFromError(error.statusCode || -1), + errorTitle: getErrorTitleFromError(error.statusCode, error.axiosCode), latency: latency, - isNae: error.statusCode === 20 ? false : true, + isNae: !( + error.statusCode === 20 || + error.axiosCode === AXIOS_CODE_NETWORK || + error.axiosCode === AXIOS_CODE_CANCELED + ), apiUrl: apiUrl, apiMethod: apiMethod, }; @@ -133,6 +139,7 @@ export const handleErrorData = ( screenMetaData, ], errorStatusCode: error.statusCode, + errorAxiosCode: error.axiosCode, }, }; setScreenData(updatedScreenData); diff --git a/App/common/utilities/ErrorUtils.ts b/App/common/utilities/ErrorUtils.ts index 9268ea1352..afacc3fc9d 100644 --- a/App/common/utilities/ErrorUtils.ts +++ b/App/common/utilities/ErrorUtils.ts @@ -1,4 +1,6 @@ import { + AXIOS_CODE_CANCELED, + AXIOS_CODE_NETWORK, AnalyticsGlobalErrorTypeConstant, ERROR_INTERNET_SUBTITLE, ERROR_INTERNET_TITLE, @@ -9,20 +11,30 @@ import { } from "../constants"; import { ErrorResponse } from "../interface/components/ErrorResponse"; -export const getErrorTypeFromStatusCode = (statusCode: number) => { +export const getErrorTypeFromStatusCode = (statusCode?: number) => { const statusCodeforGenericError = [20, 23, 24, 401, 404]; - if (statusCodeforGenericError.includes(statusCode) || statusCode >= 500) { + if ( + statusCode && + (statusCodeforGenericError.includes(statusCode) || statusCode >= 500) + ) { return AnalyticsGlobalErrorTypeConstant.GLOBAL_GENERIC_ERRORS; } return AnalyticsGlobalErrorTypeConstant.GLOBAL_INTERNAL_ERRORS; }; -export const getErrorTitleFromError = (statusCode: number) => { +export const getErrorTitleFromError = ( + statusCode?: number, + axiosCode?: string, +) => { const statusCodeforInternetIssues = [20, 21, 23, 24]; - if (statusCodeforInternetIssues.includes(statusCode)) { + if ( + (statusCode && statusCodeforInternetIssues.includes(statusCode)) || + axiosCode === AXIOS_CODE_NETWORK || + axiosCode === AXIOS_CODE_CANCELED + ) { return ERROR_INTERNET_TITLE; } @@ -31,6 +43,7 @@ export const getErrorTitleFromError = (statusCode: number) => { export const getErrorResponseFromStatusCode = ( statusCode?: number, + axiosCode?: string, ): ErrorResponse => { switch (statusCode) { case STATUS_CODE_NO_INTERNET: @@ -40,10 +53,20 @@ export const getErrorResponseFromStatusCode = ( image: ImageName.NO_INTERNET, }; default: - return { - title: ERROR_TITLE, - subtitle: ERROR_SUBTITLE, - image: ImageName.SWW, - }; + switch (axiosCode) { + case AXIOS_CODE_NETWORK: + case AXIOS_CODE_CANCELED: + return { + title: ERROR_INTERNET_TITLE, + subtitle: ERROR_INTERNET_SUBTITLE, + image: ImageName.NO_INTERNET, + }; + default: + return { + title: ERROR_TITLE, + subtitle: ERROR_SUBTITLE, + image: ImageName.SWW, + }; + } } }; diff --git a/App/common/widgets/widget-actions/WidgetActionHandler.ts b/App/common/widgets/widget-actions/WidgetActionHandler.ts index 804fd0546f..d4e0f47670 100644 --- a/App/common/widgets/widget-actions/WidgetActionHandler.ts +++ b/App/common/widgets/widget-actions/WidgetActionHandler.ts @@ -313,7 +313,7 @@ export const handleErrorData = ( moduleName: AnalyticsModuleNameConstant.GI, flowName: flowName, methodName: methodName, - globalErrorType: getErrorTypeFromStatusCode(error.statusCode || -1), + globalErrorType: getErrorTypeFromStatusCode(error.statusCode), isAppDowntimeEvent: false, isNae: false, apiUrl: apiUrl,