feat: update logEvent to silently handle errors (#5599)

This commit is contained in:
Yunus M 2024-07-30 18:24:55 +05:30 committed by GitHub
parent 738d62c9cf
commit 18b608a1d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import axios from 'api'; import { ApiBaseInstance as axios } from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios'; import { AxiosError } from 'axios';
import { ErrorResponse, SuccessResponse } from 'types/api'; import { ErrorResponse, SuccessResponse } from 'types/api';
@ -21,6 +21,7 @@ const logEvent = async (
payload: response.data.data, payload: response.data.data,
}; };
} catch (error) { } catch (error) {
console.error(error);
return ErrorResponseHandler(error as AxiosError); return ErrorResponseHandler(error as AxiosError);
} }
}; };

View File

@ -96,6 +96,10 @@ const interceptorRejected = async (
} }
}; };
const interceptorRejectedBase = async (
value: AxiosResponse<any>,
): Promise<AxiosResponse<any>> => Promise.reject(value);
const instance = axios.create({ const instance = axios.create({
baseURL: `${ENVIRONMENT.baseURL}${apiV1}`, baseURL: `${ENVIRONMENT.baseURL}${apiV1}`,
}); });
@ -140,6 +144,18 @@ ApiV4Instance.interceptors.response.use(
ApiV4Instance.interceptors.request.use(interceptorsRequestResponse); ApiV4Instance.interceptors.request.use(interceptorsRequestResponse);
// //
// axios Base
export const ApiBaseInstance = axios.create({
baseURL: `${ENVIRONMENT.baseURL}${apiV1}`,
});
ApiBaseInstance.interceptors.response.use(
interceptorsResponse,
interceptorRejectedBase,
);
ApiBaseInstance.interceptors.request.use(interceptorsRequestResponse);
//
// gateway Api V1 // gateway Api V1
export const GatewayApiV1Instance = axios.create({ export const GatewayApiV1Instance = axios.create({
baseURL: `${ENVIRONMENT.baseURL}${gatewayApiV1}`, baseURL: `${ENVIRONMENT.baseURL}${gatewayApiV1}`,

View File

@ -32,16 +32,6 @@ const useAnalytics = (): any => {
} }
}; };
// useEffect(() => {
// // Perform any setup or cleanup related to the analytics library
// // For example, initialize analytics library here
// // Clean-up function (optional)
// return () => {
// // Perform cleanup if needed
// };
// }, []); // The empty dependency array ensures that this effect runs only once when the component mounts
return { trackPageView, trackEvent }; return { trackPageView, trackEvent };
}; };