import {AxiosError, AxiosInstance, AxiosResponse} from "axios"; //import…
- User
import {AxiosError, AxiosInstance, AxiosResponse} from "axios";
//import {iMiniThermostatSettings} from "@config/types/AppDataTypes/MiniThermostatTypes"; import {WLANScanResponse,WLANSettings,WLANInfo} from "@config/types/AppDataTypes/AlthermaTypes"; import NetworkUtil from "@utils/NetworkUtil";
import {apiEndpoints} from "./axiosConfig/AxiosServiceConstants";
const AlthermaService = (apiServer: AxiosInstance) => {
/** * Generic method to handle API requests and responses * @param requestFn API request function to execute * @returns Promise with specified response */ const handleApiRequest = async ( requestFn: () => Promise<AxiosResponse> ): Promise => { try { const response = await requestFn(); return NetworkUtil.buildResult( null, response.status, null, response.data ); } catch (error) { const axiosError = error as AxiosError; if (axiosError.response) { const { status, data } = axiosError.response; return NetworkUtil.buildResult(data, status, data, null); } // throw again if the error is not an Axios error with a response throw error; } };
code/** * scan for available WiFi networks */ const scanWifiNetworks = () => handleApiRequest(() => apiServer.post(apiEndpoints.wifi.ap.scan) ); /** * Fetch the list of available WiFi networks */ const getAvailableNetworks = () => handleApiRequest<WLANScanResponse>(() => apiServer.get(apiEndpoints.wifi.ap.networks) ); /** * Configures and connects to a WiFi network */ const configureWifiConnection = (settings: WLANSettings) => handleApiRequest(() => apiServer.put(apiEndpoints.wifi.ap.settings, settings) ); /** * Gets current WLAN connection information */ const getWlanInfo = () => handleApiRequest<WLANInfo>(() => apiServer.get(apiEndpoints.wifi.ap.info) ); return { scanWifiNetworks, getAvailableNetworks, configureWifiConnection, getWlanInfo };};
export default AlthermaService; how can i avoid using any in the return type of handleApiRequest
- Assistant