в смысле обертку над axios? const requestExecutor = async (requestConfig: AxiosRequestConfig) => { const response = {data: null, error: null} try { response.data = await axios.request(requestConfig) } catch(e) { response.error = e; } return response; }
export interface RequestError { responseData: AxiosResponse | null; errorMsg: string; } export const getRequestErrorData = (e: unknown): RequestError => ({ responseData: (e as AxiosError)?.response || null, errorMsg: (e as Error)?.message, }); const requestExecutor = async (requestConfig: AxiosRequestConfig) => { const response = {data: null, error: null} try { response.data = await axios.request(requestConfig) } catch(e) { response.error = getRequestErrorData(e); } return response; }
Обсуждают сегодня