Enhance error handling, navigation, and theme management#29
Conversation
- 新增 errorMessage.js 工具模块,提供 getSafeErrorMessage / isTechnicalErrorMessage / getSafeRequestErrorMessage - request.js:使用安全错误消息替换原生错误信息,优化请求错误弹窗队列逻辑 - image.js / config.js / courseTable.js:错误信息中文化,移除技术细节 - auth.js:login/refreshToken 接口增加 handleAuthFailure 和 silent 选项
- auth.js:使用 getSafeErrorMessage 过滤技术错误信息,优化 expireToken 标题处理 - countdown.js / study-tasks.js:错误消息统一为中文友好提示
- utils/index.js:新增 safeNavigateBack,栈深度 > 1 时正常返回,否则跳转 fallback - notifications/detail、organization/detail、schedule-bind:统一使用 safeNavigateBack
- theme.js:移除原生主题 API 调用 (setNavigationBarColor/setTabBarStyle 等), 改用 CSS 变量 + theme.json 控制;getSystemInfoSync → getAppBaseInfo - useThemePage.js:移除 initTheme() 调用,仅返回 store 实例
enablePageMeta 已废弃,统一移除,改用 theme.json 全局配置
Taro.getSystemInfoSync() 已废弃,改用 getWindowInfo() 获取窗口尺寸
- teacher-reviews:统一 class 属性缩进格式,修复 scroll-view 滚动属性写法 - gpa-calculator:调整 scroll-view 内部 padding 结构,修复内容两侧间距问题
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements to the application, including the removal of redundant page meta configurations, the simplification of user-facing toast messages, and the cleanup of theme store actions. It also introduces a new errorMessage utility to sanitize technical errors and a safeNavigateBack helper to prevent navigation issues when the history stack is empty. Additionally, modern Taro APIs like getWindowInfo and getAppBaseInfo are adopted. Feedback on these changes suggests passing the original error message to expireToken() in request.js to preserve user-friendly server messages, and wrapping Taro.getWindowInfo() in a try-catch block with a fallback to ensure compatibility with older WeChat clients.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| useAuthStore().expireToken(finalError.message || '请重新登录') | ||
| if (finalError?.isAuthError) { | ||
| if (handleAuthFailure) { | ||
| useAuthStore().expireToken() |
There was a problem hiding this comment.
Calling expireToken() without any arguments discards finalError?.message entirely. This means the user will always see the default '请重新登录' toast, even if the server returned a specific, user-friendly message (e.g., '您的账号在其他设备登录').
By passing finalError?.message to expireToken(), we allow normalizeExpireTokenTitle to sanitize and display the specific message if it is not a technical error, while still falling back to '请重新登录' if it is technical or empty.
| useAuthStore().expireToken() | |
| useAuthStore().expireToken(finalError?.message) |
| const windowInfo = Taro.getWindowInfo() | ||
| chartWidth.value = Math.max(280, Math.floor((windowInfo.windowWidth || 375) - 56)) |
There was a problem hiding this comment.
Calling Taro.getWindowInfo() directly without a try-catch block or a fallback check can cause runtime crashes on older WeChat clients or non-WeChat platforms where this API is not supported.
To ensure maximum compatibility and robustness, wrap the call in a try-catch block and fall back to Taro.getSystemInfoSync() or a default value if Taro.getWindowInfo is unavailable.
let windowWidth = 375
try {
if (typeof Taro.getWindowInfo === 'function') {
windowWidth = Taro.getWindowInfo().windowWidth || 375
} else if (typeof Taro.getSystemInfoSync === 'function') {
windowWidth = Taro.getSystemInfoSync().windowWidth || 375
}
} catch (error) {
console.warn('Failed to get window width:', error)
}
chartWidth.value = Math.max(280, Math.floor(windowWidth - 56))
This pull request includes several improvements and adjustments across the codebase, mainly focusing on localization of user-facing messages, API parameter enhancements, UI consistency, and minor bug fixes. The most significant changes are grouped and summarized below.
Localization and User-Facing Message Updates:
API and Logic Enhancements:
handleAuthFailureandsilent) for more granular control over authentication behavior. [1] [2]UI and Page Configuration Adjustments:
enablePageMeta: trueproperty from multiple page configuration files, likely for consistency or to address compatibility issues. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Code and Logic Simplification:
useThemePagecomposable by removing unnecessary initialization logic, returning the theme store directly.final-review/detailto useTaro.getWindowInfo()instead ofTaro.getSystemInfoSync()for obtaining window height, improving reliability.UI Bug Fixes and Improvements:
These changes collectively improve localization, user experience, code maintainability, and UI consistency across the application.