73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import {
|
|
AXIOS_CODE_CANCELED,
|
|
AXIOS_CODE_NETWORK,
|
|
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 (
|
|
statusCode &&
|
|
(statusCodeforGenericError.includes(statusCode) || statusCode >= 500)
|
|
) {
|
|
return AnalyticsGlobalErrorTypeConstant.GLOBAL_GENERIC_ERRORS;
|
|
}
|
|
|
|
return AnalyticsGlobalErrorTypeConstant.GLOBAL_INTERNAL_ERRORS;
|
|
};
|
|
|
|
export const getErrorTitleFromError = (
|
|
statusCode?: number,
|
|
axiosCode?: string,
|
|
) => {
|
|
const statusCodeforInternetIssues = [20, 21, 23, 24];
|
|
|
|
if (
|
|
(statusCode && statusCodeforInternetIssues.includes(statusCode)) ||
|
|
axiosCode === AXIOS_CODE_NETWORK ||
|
|
axiosCode === AXIOS_CODE_CANCELED
|
|
) {
|
|
return ERROR_INTERNET_TITLE;
|
|
}
|
|
|
|
return ERROR_TITLE;
|
|
};
|
|
|
|
export const getErrorResponseFromStatusCode = (
|
|
statusCode?: number,
|
|
axiosCode?: string,
|
|
): ErrorResponse => {
|
|
switch (statusCode) {
|
|
case STATUS_CODE_NO_INTERNET:
|
|
return {
|
|
title: ERROR_INTERNET_TITLE,
|
|
subtitle: ERROR_INTERNET_SUBTITLE,
|
|
image: ImageName.NO_INTERNET,
|
|
};
|
|
default:
|
|
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,
|
|
};
|
|
}
|
|
}
|
|
};
|