|
|
@@ -91,6 +91,9 @@ const generateSign = (id: string, time: number, token: string, secret: string, b
|
|
|
export const createRequestNative = () => {
|
|
|
const runtimeConfig = useRuntimeConfig()
|
|
|
const { token, logout } = useAuth()
|
|
|
+ const nuxtApp = useNuxtApp()
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
+ const t = ((nuxtApp as any)?.$i18n?.t?.bind((nuxtApp as any)?.$i18n) as ((key: string) => string) | undefined) || ((key: string) => key)
|
|
|
|
|
|
const API_CONFIG = {
|
|
|
baseURL: runtimeConfig.public.apiBase || '/api',
|
|
|
@@ -108,7 +111,7 @@ export const createRequestNative = () => {
|
|
|
const raw = window.GAMI_BRIDGE?.requestHeader
|
|
|
if (!raw || typeof raw !== 'object') {
|
|
|
console.error('Must in native context')
|
|
|
- showError('Must in native context')
|
|
|
+ showError(t('common.errors.nativeOnly'))
|
|
|
|
|
|
return {}
|
|
|
}
|
|
|
@@ -194,7 +197,7 @@ export const createRequestNative = () => {
|
|
|
}
|
|
|
|
|
|
handleApiError(data.code, data.msg)
|
|
|
- throw new Error(data.msg || 'Request failed')
|
|
|
+ throw new Error(data.msg || t('common.errors.requestFailed'))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -211,23 +214,23 @@ export const createRequestNative = () => {
|
|
|
handleUnauthorized()
|
|
|
break
|
|
|
case 403:
|
|
|
- showError('No permission to access this resource')
|
|
|
+ showError(t('common.errors.noPermission'))
|
|
|
break
|
|
|
case 404:
|
|
|
- showError('Resource not found')
|
|
|
+ showError(t('common.errors.notFound'))
|
|
|
break
|
|
|
case 500:
|
|
|
- showError('Server error, please try again later')
|
|
|
+ showError(t('common.errors.serverError'))
|
|
|
break
|
|
|
default:
|
|
|
- showError(data?.msg || error?.message || 'Request failed')
|
|
|
+ showError(data?.msg || error?.message || t('common.errors.requestFailed'))
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
const message = error?.message || ''
|
|
|
- if (message.includes('timeout')) showError('Request timeout, please try again')
|
|
|
- else if (message.includes('Network Error')) showError('Network error, please check your connection')
|
|
|
- else showError(message || 'Unknown error occurred')
|
|
|
+ if (message.includes('timeout')) showError(t('common.errors.timeout'))
|
|
|
+ else if (message.includes('Network Error')) showError(t('common.errors.network'))
|
|
|
+ else showError(message || t('common.errors.unknownError'))
|
|
|
}
|
|
|
|
|
|
return Promise.reject(error)
|
|
|
@@ -249,7 +252,7 @@ export const createRequestNative = () => {
|
|
|
const route = useRoute()
|
|
|
const redirect = route.fullPath
|
|
|
|
|
|
- showError('Login expired, please login again')
|
|
|
+ showError(t('common.errors.loginExpired'))
|
|
|
navigateTo({
|
|
|
path: '/login',
|
|
|
query: redirect && redirect !== '/login' ? { redirect } : undefined,
|