@@ -93,3 +93,31 @@ export function calendarModeLabel(mode: string) {
|
||||
export function shouldToggleRowSwipe(deltaX: number, deltaY: number) {
|
||||
return deltaX >= 64 && deltaX > Math.abs(deltaY) * 1.5
|
||||
}
|
||||
|
||||
export function nextTotalAfterLocalTaskAdd(total: number) {
|
||||
return Math.max(0, Number(total) || 0) + 1
|
||||
}
|
||||
|
||||
export function formatApiErrorDetail(detail: unknown): string {
|
||||
if (typeof detail === 'string') return detail
|
||||
if (Array.isArray(detail)) {
|
||||
const messages = detail.map((item) => {
|
||||
if (item && typeof item === 'object') {
|
||||
const record = item as Record<string, unknown>
|
||||
const location = Array.isArray(record.loc)
|
||||
? record.loc.filter((part) => part !== 'body').join('.')
|
||||
: ''
|
||||
const message = typeof record.msg === 'string' ? record.msg : JSON.stringify(record)
|
||||
return location ? `${location}:${message}` : message
|
||||
}
|
||||
return String(item)
|
||||
})
|
||||
return messages.filter(Boolean).join(';') || '请求参数有误'
|
||||
}
|
||||
if (detail && typeof detail === 'object') {
|
||||
const record = detail as Record<string, unknown>
|
||||
if ('detail' in record) return formatApiErrorDetail(record.detail)
|
||||
return JSON.stringify(record)
|
||||
}
|
||||
return '请求失败'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user