mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
Add network error catch
This commit is contained in:
parent
fdfbad68e2
commit
ccd8d2b6b0
4 changed files with 29 additions and 5 deletions
|
|
@ -144,6 +144,7 @@
|
||||||
"localFontAccessDenied": "access denied to local fonts",
|
"localFontAccessDenied": "access denied to local fonts",
|
||||||
"loginRateError": "too many login attempts, please try again in a few seconds",
|
"loginRateError": "too many login attempts, please try again in a few seconds",
|
||||||
"mpvRequired": "MPV required",
|
"mpvRequired": "MPV required",
|
||||||
|
"networkError": "a network error occurred",
|
||||||
"playbackError": "an error occurred when trying to play the media",
|
"playbackError": "an error occurred when trying to play the media",
|
||||||
"remoteDisableError": "an error occurred when trying to $t(common.disable) the remote server",
|
"remoteDisableError": "an error occurred when trying to $t(common.disable) the remote server",
|
||||||
"remoteEnableError": "an error occurred when trying to $t(common.enable) the remote server",
|
"remoteEnableError": "an error occurred when trying to $t(common.enable) the remote server",
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { ServerListItem } from '/@/renderer/types';
|
||||||
import omitBy from 'lodash/omitBy';
|
import omitBy from 'lodash/omitBy';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { authenticationFailure } from '/@/renderer/api/utils';
|
import { authenticationFailure } from '/@/renderer/api/utils';
|
||||||
|
import i18n from '/@/i18n/i18n';
|
||||||
|
|
||||||
const c = initContract();
|
const c = initContract();
|
||||||
|
|
||||||
|
|
@ -337,6 +338,14 @@ export const jfApiClient = (args: {
|
||||||
};
|
};
|
||||||
} catch (e: Error | AxiosError | any) {
|
} catch (e: Error | AxiosError | any) {
|
||||||
if (isAxiosError(e)) {
|
if (isAxiosError(e)) {
|
||||||
|
if (e.code === 'ERR_NETWORK') {
|
||||||
|
throw new Error(
|
||||||
|
i18n.t('error.networkError', {
|
||||||
|
postProcess: 'sentenceCase',
|
||||||
|
}) as string,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const error = e as AxiosError;
|
const error = e as AxiosError;
|
||||||
const response = error.response as AxiosResponse;
|
const response = error.response as AxiosResponse;
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -380,12 +380,20 @@ export const ndApiClient = (args: {
|
||||||
};
|
};
|
||||||
} catch (e: Error | AxiosError | any) {
|
} catch (e: Error | AxiosError | any) {
|
||||||
if (isAxiosError(e)) {
|
if (isAxiosError(e)) {
|
||||||
|
if (e.code === 'ERR_NETWORK') {
|
||||||
|
throw new Error(
|
||||||
|
i18n.t('error.networkError', {
|
||||||
|
postProcess: 'sentenceCase',
|
||||||
|
}) as string,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const error = e as AxiosError;
|
const error = e as AxiosError;
|
||||||
const response = error.response as AxiosResponse;
|
const response = error.response as AxiosResponse;
|
||||||
return {
|
return {
|
||||||
body: { data: response.data, headers: response.headers },
|
body: { data: response?.data, headers: response?.headers },
|
||||||
headers: response.headers as any,
|
headers: response?.headers as any,
|
||||||
status: response.status,
|
status: response?.status,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
||||||
|
|
@ -185,9 +185,15 @@ export const ssApiClient = (args: {
|
||||||
status: result.status,
|
status: result.status,
|
||||||
};
|
};
|
||||||
} catch (e: Error | AxiosError | any) {
|
} catch (e: Error | AxiosError | any) {
|
||||||
console.log('CATCH ERR');
|
|
||||||
|
|
||||||
if (isAxiosError(e)) {
|
if (isAxiosError(e)) {
|
||||||
|
if (e.code === 'ERR_NETWORK') {
|
||||||
|
throw new Error(
|
||||||
|
i18n.t('error.networkError', {
|
||||||
|
postProcess: 'sentenceCase',
|
||||||
|
}) as string,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const error = e as AxiosError;
|
const error = e as AxiosError;
|
||||||
const response = error.response as AxiosResponse;
|
const response = error.response as AxiosResponse;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue