1. 修复 SDK 文档 API 路由顺序问题
- 将静态路由 /sdk-docs, /test-script, /secrets 移到动态路由 /{task_id} 之前
- 解决 "请求参数验证失败" 错误
2. 优化错误页面体验
- 使用 sessionStorage 传递错误信息,URL 保持干净
- 使用 router.replace 替代 push,浏览器返回不会停留在错误页
- 记录来源页面,支持正确返回
3. 增强网络错误处理
- 区分超时、网络错误、服务不可用
- 后端未启动时显示友好的 "服务暂时不可用" 提示
4. 添加定时任务模块文档
This commit is contained in:
@@ -18,9 +18,21 @@ function parseApiError(error) {
|
||||
status: 500
|
||||
}
|
||||
|
||||
// 网络错误(后端未启动、网络断开等)
|
||||
if (!error.response) {
|
||||
result.code = 'NETWORK_ERROR'
|
||||
result.message = '网络连接失败,请检查网络后重试'
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
result.code = 'TIMEOUT_ERROR'
|
||||
result.message = '请求超时,请稍后重试'
|
||||
result.status = 0
|
||||
} else if (error.message?.includes('Network Error')) {
|
||||
result.code = 'SERVICE_UNAVAILABLE'
|
||||
result.message = '服务暂时不可用,请稍后重试'
|
||||
result.status = 503
|
||||
} else {
|
||||
result.code = 'NETWORK_ERROR'
|
||||
result.message = '网络连接失败,请检查网络后重试'
|
||||
result.status = 0
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -40,18 +52,23 @@ function parseApiError(error) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到错误页面
|
||||
* 跳转到错误页面(使用 sessionStorage + replace,不影响浏览器历史)
|
||||
*/
|
||||
function navigateToErrorPage(errorInfo) {
|
||||
router.push({
|
||||
name: 'Error',
|
||||
query: {
|
||||
code: errorInfo.code,
|
||||
message: errorInfo.message,
|
||||
trace_id: errorInfo.traceId,
|
||||
status: String(errorInfo.status)
|
||||
}
|
||||
})
|
||||
// 记录当前页面路径(用于返回)
|
||||
sessionStorage.setItem('errorFromPath', router.currentRoute.value.fullPath)
|
||||
|
||||
// 保存错误信息到 sessionStorage(不会显示在 URL 中)
|
||||
sessionStorage.setItem('errorInfo', JSON.stringify({
|
||||
code: errorInfo.code,
|
||||
message: errorInfo.message,
|
||||
traceId: errorInfo.traceId,
|
||||
status: errorInfo.status,
|
||||
timestamp: Date.now()
|
||||
}))
|
||||
|
||||
// 使用 replace 而不是 push,这样浏览器返回时不会停留在错误页
|
||||
router.replace({ name: 'Error' })
|
||||
}
|
||||
|
||||
// 请求拦截器
|
||||
@@ -75,6 +92,15 @@ api.interceptors.response.use(
|
||||
|
||||
console.error(`[API Error] ${errorInfo.code}: ${errorInfo.message}${traceLog}`)
|
||||
|
||||
// 严重错误列表(跳转错误页)
|
||||
const criticalErrors = [
|
||||
'INTERNAL_ERROR',
|
||||
'SERVICE_UNAVAILABLE',
|
||||
'GATEWAY_ERROR',
|
||||
'NETWORK_ERROR',
|
||||
'TIMEOUT_ERROR'
|
||||
]
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('user')
|
||||
@@ -82,8 +108,8 @@ api.interceptors.response.use(
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
} else if (error.response?.status === 403) {
|
||||
ElMessage.error('没有权限执行此操作')
|
||||
} else if (['INTERNAL_ERROR', 'SERVICE_UNAVAILABLE', 'GATEWAY_ERROR'].includes(errorInfo.code)) {
|
||||
// 严重错误跳转到错误页面
|
||||
} else if (criticalErrors.includes(errorInfo.code)) {
|
||||
// 严重错误(包括网络错误、服务不可用)跳转到错误页面
|
||||
navigateToErrorPage(errorInfo)
|
||||
} else {
|
||||
// 普通错误显示消息
|
||||
|
||||
Reference in New Issue
Block a user