From 5f2248001dacc838e8aba339de66e7bb7ff3e10b Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Mon, 25 May 2026 21:09:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(client):=20Dio=20=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E7=BB=9F=E4=B8=80=E4=B8=8A=E6=8A=A5=205xx=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=8C=E6=96=B0=E5=A2=9E=20api=5Ferror=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- client/lib/core/api/api_client.dart | 11 +++++++++++ client/lib/core/errors/error_reporter.dart | 1 + 2 files changed, 12 insertions(+) diff --git a/client/lib/core/api/api_client.dart b/client/lib/core/api/api_client.dart index de1528a..f7f1b74 100644 --- a/client/lib/core/api/api_client.dart +++ b/client/lib/core/api/api_client.dart @@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../auth/auth_state.dart'; import '../config/app_config.dart'; +import '../errors/error_reporter.dart'; import '../../providers/connectivity_provider.dart'; /// Public Dio instance for unauthenticated calls (login / refresh) @@ -74,6 +75,16 @@ class ApiClient { return handler.next(e); } + // 服务端 5xx 错误上报(4xx 是业务/权限错误,不上报) + final statusCode = e.response?.statusCode ?? 0; + if (statusCode >= 500) { + reportError( + '[${e.requestOptions.method}] ${e.requestOptions.path} → $statusCode', + e.stackTrace, + errorType: ErrorType.apiError, + ); + } + if (e.response?.statusCode == 401 && (refreshToken ?? '').isNotEmpty) { debugPrint('[ApiClient] got 401 on ${e.requestOptions.path}, trying refresh...'); try { diff --git a/client/lib/core/errors/error_reporter.dart b/client/lib/core/errors/error_reporter.dart index d6f51ad..b5c5d7e 100644 --- a/client/lib/core/errors/error_reporter.dart +++ b/client/lib/core/errors/error_reporter.dart @@ -12,6 +12,7 @@ class ErrorType { static const flutterError = 'flutter_error'; static const zoneError = 'zone_error'; static const caughtException = 'caught_exception'; + static const apiError = 'api_error'; } class ErrorReporter {