From 97ca4c7f72c876eb31efb58784671fa4e733feca Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Thu, 30 Apr 2026 19:39:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(client):=20=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=9D=99=E9=BB=98=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 捕获所有异常(非仅 DioException),兼容 ImportProducts 响应格式(无 total/skipped), 确保任何错误都在 UI 上显示而不是静默消失。 Co-Authored-By: Claude Sonnet 4.6 --- client/lib/screens/settings/settings_screen.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/lib/screens/settings/settings_screen.dart b/client/lib/screens/settings/settings_screen.dart index 6e8b4bf..32c7bd8 100644 --- a/client/lib/screens/settings/settings_screen.dart +++ b/client/lib/screens/settings/settings_screen.dart @@ -1514,19 +1514,25 @@ class _BatchImportWidgetState extends ConsumerState<_BatchImportWidget> { 'file': MultipartFile.fromBytes(bytes, filename: slot.file!.name), }); final resp = await dio.post(slot.endpoint, data: formData); - final data = resp.data as Map; + final data = (resp.data is Map) ? resp.data as Map : {}; if (mounted) setState(() { slot.success = true; - slot.total = (data['total'] ?? 0) as int; + slot.total = (data['total'] ?? data['imported'] ?? 0) as int; slot.imported = (data['imported'] ?? 0) as int; slot.skipped = (data['skipped'] ?? 0) as int; }); } on DioException catch (e) { - final msg = (e.response?.data as Map?)?['error'] ?? e.message ?? '未知错误'; + final raw = e.response?.data; + final msg = (raw is Map ? raw['error'] : null) ?? e.message ?? '未知错误'; if (mounted) setState(() { slot.success = false; slot.error = msg.toString(); }); + } catch (e) { + if (mounted) setState(() { + slot.success = false; + slot.error = e.toString(); + }); } }