export function getErrorMessage(error: unknown): string { if (typeof error === 'string') return error; const message = error instanceof Error ? error.message : '未知错误'; // Postgres/Supabase errors if (message.includes('invalid input syntax for type uuid')) { return 'ID 格式错误 (UUID)'; } if (message.includes('duplicate key value violates unique constraint')) { return '数据已存在,请勿重复添加'; } if (message.includes('violates foreign key constraint')) { return '关联数据不存在或已被删除'; } if (message.includes('violates not-null constraint')) { return '必填项不能为空'; } if (message.includes('JSON object requested, multiple (or no) rows returned')) { return '数据查询错误:未找到记录或返回多条记录'; } if (message.includes('Failed to fetch')) { return '网络请求失败,请检查网络连接'; } return message; }