feat(client): Dio 拦截器统一上报 5xx 错误,新增 api_error 类型
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user