Co-authored-by: shrihari-raju_navi <shrihari.raju@navi.com> Co-authored-by: Kshitij Pramod Ghongadi <kshitij.pramod@navi.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import {
|
|
AnalyticsGlobalErrorTypeConstant,
|
|
ERROR_INTERNET_SUBTITLE,
|
|
ERROR_INTERNET_TITLE,
|
|
ERROR_SUBTITLE,
|
|
ERROR_TITLE,
|
|
ImageName,
|
|
STATUS_CODE_NO_INTERNET,
|
|
} from "../constants";
|
|
import { ErrorResponse } from "../interface/components/ErrorResponse";
|
|
|
|
export const getErrorTypeFromStatusCode = (statusCode: number) => {
|
|
const statusCodeforGenericError = [20, 23, 24, 401, 404];
|
|
|
|
if (statusCodeforGenericError.includes(statusCode) || statusCode >= 500) {
|
|
return AnalyticsGlobalErrorTypeConstant.GLOBAL_GENERIC_ERRORS;
|
|
}
|
|
|
|
return AnalyticsGlobalErrorTypeConstant.GLOBAL_INTERNAL_ERRORS;
|
|
};
|
|
|
|
export const getErrorTitleFromError = (statusCode: number) => {
|
|
const statusCodeforInternetIssues = [20, 21, 23, 24];
|
|
|
|
if (statusCodeforInternetIssues.includes(statusCode)) {
|
|
return ERROR_INTERNET_TITLE;
|
|
}
|
|
|
|
return ERROR_TITLE;
|
|
};
|
|
|
|
export const getErrorResponseFromStatusCode = (
|
|
statusCode?: number,
|
|
): ErrorResponse => {
|
|
switch (statusCode) {
|
|
case STATUS_CODE_NO_INTERNET:
|
|
return {
|
|
title: ERROR_INTERNET_TITLE,
|
|
subtitle: ERROR_INTERNET_SUBTITLE,
|
|
image: ImageName.NO_INTERNET,
|
|
};
|
|
default:
|
|
return {
|
|
title: ERROR_TITLE,
|
|
subtitle: ERROR_SUBTITLE,
|
|
image: ImageName.SWW,
|
|
};
|
|
}
|
|
};
|