Skip to content

Commit

Permalink
Update axiosInterceptor.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming committed Nov 5, 2024
1 parent 84b4bca commit e561f28
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/shared/src/request/axiosInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */
/* eslint-disable @typescript-eslint/unbound-method */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

import axios, { AxiosError } from 'axios';
import { forEach } from 'lodash';
import { debounce, forEach } from 'lodash';

import { OneKeyError, OneKeyServerApiError } from '@onekeyhq/shared/src/errors';
import { refresh } from '@onekeyhq/shared/src/modules3rdParty/@react-native-community/netinfo';
import type { IOneKeyAPIBaseResponse } from '@onekeyhq/shared/types/request';

import { EOneKeyErrorClassNames } from '../errors/types/errorTypes';
Expand All @@ -22,6 +24,10 @@ import {

import type { AxiosInstance, AxiosRequestConfig } from 'axios';

const refreshNetInfo = debounce(() => {
void refresh();
}, 1000);

axios.interceptors.request.use(async (config) => {
if (config.timeout === undefined) {
config.timeout = 30_000;
Expand Down Expand Up @@ -146,6 +152,7 @@ axios.interceptors.response.use(
error.code === AxiosError.ERR_NETWORK &&
error.name === 'AxiosError'
) {
refreshNetInfo();
const title = appLocale.intl.formatMessage({
id: ETranslations.global_network_error,
});
Expand Down

0 comments on commit e561f28

Please sign in to comment.