feat: 添加用户虚拟机商品管理
This commit is contained in:
@@ -138,6 +138,13 @@ function parseRpcError(err) {
|
||||
export function extractApiError(body, fallback = '操作失败') {
|
||||
if (!body) return fallback
|
||||
|
||||
// 识别数据库唯一约束冲突
|
||||
if (body.error && body.error.includes('duplicate key value violates unique constraint')) {
|
||||
const nameMatch = body.error.match(/create \w+ \[(.+?)\] error/)
|
||||
const hint = nameMatch ? `「${nameMatch[1]}」已存在,请勿重复生成` : '数据已存在,请勿重复操作'
|
||||
return hint
|
||||
}
|
||||
|
||||
const rpcMsg = parseRpcError(body.error)
|
||||
if (rpcMsg) return rpcMsg
|
||||
|
||||
|
||||
+14
-1
@@ -108,4 +108,17 @@ export function isoToMilliseconds(time) {
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间为 "YYYY-MM-DD HH:mm:ss" 格式(用于接口提交)
|
||||
* @param {string|Date|number} time
|
||||
* @returns {string} 格式化后的时间字符串,无效时返回 ''
|
||||
*/
|
||||
export function formatToApiTime(time) {
|
||||
if (!time) return ''
|
||||
const d = time instanceof Date ? time : new Date(time)
|
||||
if (isNaN(d.getTime())) return ''
|
||||
const pad = (n) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user