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 {