fix: 修复 Toast 未定义导致 fetch 拦截器崩溃

- 添加 Toast 调用的 try-catch 安全检查
- 修复 "Cannot read properties of undefined (reading 'show')" 错误
- 确保 fetch 拦截器在 Toast 未初始化时也能正常工作

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
imeepos 2026-01-13 16:06:47 +08:00
parent 2d0a21205f
commit 99e2c5fafc
1 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { router } from 'expo-router';
import { Toast } from '@/components/ui/Toast';
import Toast from '@/components/ui/Toast';
import { storage } from './storage';
@ -80,8 +80,12 @@ export const createFetchWithLogger = (options: FetchLoggerOptions = {}) => {
console.warn('🔐 401 未授权,跳转到登录页')
isRedirecting = true
// 显示 Toast 提示
Toast.show('登录已过期,请重新登录')
// 显示 Toast 提示(安全检查)
try {
Toast.show('登录已过期,请重新登录')
} catch (error) {
console.warn('[Toast] 显示失败:', error)
}
// 清除过期 Token
await storage.removeItem(TOKEN_KEY)