Auto backup \2026-\04-\20
This commit is contained in:
@@ -10,6 +10,7 @@ import { postsApi } from '../api/posts'
|
|||||||
import { categoriesApi } from '../api/categories'
|
import { categoriesApi } from '../api/categories'
|
||||||
import { tagsApi } from '../api/tags'
|
import { tagsApi } from '../api/tags'
|
||||||
import { API_BASE_URL } from '../api/config'
|
import { API_BASE_URL } from '../api/config'
|
||||||
|
import { getErrorMessage } from '../utils/errorMessage'
|
||||||
|
|
||||||
// 错误弹窗组件
|
// 错误弹窗组件
|
||||||
function ErrorModal({ message, onClose, onClear }) {
|
function ErrorModal({ message, onClose, onClear }) {
|
||||||
@@ -228,7 +229,7 @@ export function CrawlEdit() {
|
|||||||
await postsApi.createPost(data)
|
await postsApi.createPost(data)
|
||||||
navigate('/admin/posts')
|
navigate('/admin/posts')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert('保存失败: ' + (error.response?.data?.detail || '未知错误'))
|
alert('保存失败: ' + getErrorMessage(error))
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { postsApi } from '../api/posts'
|
|||||||
import { categoriesApi } from '../api/categories'
|
import { categoriesApi } from '../api/categories'
|
||||||
import { tagsApi } from '../api/tags'
|
import { tagsApi } from '../api/tags'
|
||||||
import { API_BASE_URL } from '../api/config'
|
import { API_BASE_URL } from '../api/config'
|
||||||
|
import { getErrorMessage } from '../utils/errorMessage'
|
||||||
|
|
||||||
import MDEditor from '@uiw/react-md-editor'
|
import MDEditor from '@uiw/react-md-editor'
|
||||||
import '@uiw/react-md-editor/markdown-editor.css'
|
import '@uiw/react-md-editor/markdown-editor.css'
|
||||||
@@ -247,7 +248,7 @@ export function PostEdit() {
|
|||||||
|
|
||||||
navigate('/admin/posts')
|
navigate('/admin/posts')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert('保存失败: ' + (error.response?.data?.detail || '未知错误'))
|
alert('保存失败: ' + getErrorMessage(error))
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { Input, Textarea, Label, FormError } from '../components-preline/Input'
|
|||||||
import { categoriesApi } from '../api/categories'
|
import { categoriesApi } from '../api/categories'
|
||||||
import { tagsApi } from '../api/tags'
|
import { tagsApi } from '../api/tags'
|
||||||
import { API_BASE_URL } from '../api/config'
|
import { API_BASE_URL } from '../api/config'
|
||||||
|
import { getErrorMessage } from '../utils/errorMessage'
|
||||||
|
|
||||||
// 错误弹窗组件
|
// 错误弹窗组件
|
||||||
function ErrorModal({ message, onClose, onClear }) {
|
function ErrorModal({ message, onClose, onClear }) {
|
||||||
@@ -247,7 +248,7 @@ export function UniversalCrawlEdit() {
|
|||||||
|
|
||||||
navigate('/admin/posts')
|
navigate('/admin/posts')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert('保存失败: ' + (error.message || error.response?.data?.detail || '未知错误'))
|
alert('保存失败: ' + getErrorMessage(error))
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter } fr
|
|||||||
import { Button } from '../../components-preline/Button'
|
import { Button } from '../../components-preline/Button'
|
||||||
import { Input, Textarea, Label } from '../../components-preline/Input'
|
import { Input, Textarea, Label } from '../../components-preline/Input'
|
||||||
import { categoriesApi } from '../../api/categories'
|
import { categoriesApi } from '../../api/categories'
|
||||||
|
import { getErrorMessage } from '../../utils/errorMessage'
|
||||||
|
|
||||||
// 分类列表项
|
// 分类列表项
|
||||||
function CategoryItem({ category, isEditing, onEdit, onDelete }) {
|
function CategoryItem({ category, isEditing, onEdit, onDelete }) {
|
||||||
@@ -134,7 +135,7 @@ export function Categories() {
|
|||||||
}
|
}
|
||||||
fetchCategories()
|
fetchCategories()
|
||||||
} catch (error) {
|
} 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user