Auto backup \2026-\04-\20

This commit is contained in:
Ubuntu
2026-08-16 16:00:02 +08:00
parent 4d1773ca9c
commit 2456ad983c
5 changed files with 23 additions and 4 deletions
@@ -10,6 +10,7 @@ import { postsApi } from '../api/posts'
import { categoriesApi } from '../api/categories'
import { tagsApi } from '../api/tags'
import { API_BASE_URL } from '../api/config'
import { getErrorMessage } from '../utils/errorMessage'
// 错误弹窗组件
function ErrorModal({ message, onClose, onClear }) {
@@ -228,7 +229,7 @@ export function CrawlEdit() {
await postsApi.createPost(data)
navigate('/admin/posts')
} catch (error) {
alert('保存失败: ' + (error.response?.data?.detail || '未知错误'))
alert('保存失败: ' + getErrorMessage(error))
} finally {
setSaving(false)
}
@@ -10,6 +10,7 @@ import { postsApi } from '../api/posts'
import { categoriesApi } from '../api/categories'
import { tagsApi } from '../api/tags'
import { API_BASE_URL } from '../api/config'
import { getErrorMessage } from '../utils/errorMessage'
import MDEditor from '@uiw/react-md-editor'
import '@uiw/react-md-editor/markdown-editor.css'
@@ -247,7 +248,7 @@ export function PostEdit() {
navigate('/admin/posts')
} catch (error) {
alert('保存失败: ' + (error.response?.data?.detail || '未知错误'))
alert('保存失败: ' + getErrorMessage(error))
} finally {
setSaving(false)
}
@@ -9,6 +9,7 @@ import { Input, Textarea, Label, FormError } from '../components-preline/Input'
import { categoriesApi } from '../api/categories'
import { tagsApi } from '../api/tags'
import { API_BASE_URL } from '../api/config'
import { getErrorMessage } from '../utils/errorMessage'
// 错误弹窗组件
function ErrorModal({ message, onClose, onClear }) {
@@ -247,7 +248,7 @@ export function UniversalCrawlEdit() {
navigate('/admin/posts')
} catch (error) {
alert('保存失败: ' + (error.message || error.response?.data?.detail || '未知错误'))
alert('保存失败: ' + getErrorMessage(error))
} finally {
setSaving(false)
}
@@ -6,6 +6,7 @@ import { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter } fr
import { Button } from '../../components-preline/Button'
import { Input, Textarea, Label } from '../../components-preline/Input'
import { categoriesApi } from '../../api/categories'
import { getErrorMessage } from '../../utils/errorMessage'
// 分类列表项
function CategoryItem({ category, isEditing, onEdit, onDelete }) {
@@ -134,7 +135,7 @@ export function Categories() {
}
fetchCategories()
} catch (error) {
alert('删除失败: ' + (error.response?.data?.detail || '未知错误'))
alert('删除失败: ' + getErrorMessage(error))
}
}
@@ -0,0 +1,15 @@
// 统一错误信息提取
// 优先级:服务端 detail > 网络异常提示 > error.message > 兜底文案
export function getErrorMessage(error, fallback = '未知错误') {
if (error?.response?.data?.detail) return error.response.data.detail
// axios 网络错误(ERR_NETWORK/超时) 或 fetch 网络错误(TypeError) 归为网络异常
if (
error?.code === 'ERR_NETWORK' ||
error?.code === 'ECONNABORTED' ||
error?.name === 'TypeError' ||
/network error|failed to fetch|timeout|timed out/i.test(error?.message || '')
) {
return '网络异常,请检查网络连接后重试'
}
return error?.message || fallback
}