11// ignore_for_file: type_literal_in_constant_pattern
22
33import 'package:dio/dio.dart' ;
4- import 'package:flutter/foundation.dart' ;
54import 'package:gsy_github_app_flutter/common/config/config.dart' ;
5+ import 'package:gsy_github_app_flutter/common/logger.dart' ;
66
77/// Log 拦截器
88/// Created by guoshuyu
@@ -20,17 +20,11 @@ class LogsInterceptors extends InterceptorsWrapper {
2020 @override
2121 onRequest (RequestOptions options, handler) async {
2222 if (Config .DEBUG ! ) {
23- if (kDebugMode) {
24- print ("请求url:${options .path } ${options .method }" );
25- }
23+ printLog ("请求url:${options .path } ${options .method }" );
2624 options.headers.forEach ((k, v) => options.headers[k] = v ?? "" );
27- if (kDebugMode) {
28- print ('请求头: ${options .headers }' );
29- }
25+ printLog ('请求头: ${options .headers }' );
3026 if (options.data != null ) {
31- if (kDebugMode) {
32- print ('请求参数: ${options .data }' );
33- }
27+ printLog ('请求参数: ${options .data }' );
3428 }
3529 }
3630 try {
@@ -49,19 +43,15 @@ class LogsInterceptors extends InterceptorsWrapper {
4943 }
5044 addLogic (sHttpRequest, map);
5145 } catch (e) {
52- if (kDebugMode) {
53- print (e);
54- }
46+ printLog (e);
5547 }
5648 return super .onRequest (options, handler);
5749 }
5850
5951 @override
6052 onResponse (Response response, handler) async {
6153 if (Config .DEBUG ! ) {
62- if (kDebugMode) {
63- print ('返回参数: $response ' );
64- }
54+ printLog ('返回参数: $response ' );
6555 }
6656 switch (response.data.runtimeType) {
6757 case Map || List :
@@ -72,9 +62,7 @@ class LogsInterceptors extends InterceptorsWrapper {
7262 addLogic (sResponsesHttpUrl, response.requestOptions.uri.toString ());
7363 addLogic (sHttpResponses, data);
7464 } catch (e) {
75- if (kDebugMode) {
76- print (e);
77- }
65+ printLog (e);
7866 }
7967 }
8068 case String :
@@ -85,9 +73,7 @@ class LogsInterceptors extends InterceptorsWrapper {
8573 addLogic (sResponsesHttpUrl, response.requestOptions.uri.toString ());
8674 addLogic (sHttpResponses, data);
8775 } catch (e) {
88- if (kDebugMode) {
89- print (e);
90- }
76+ printLog (e);
9177 }
9278 }
9379 }
@@ -97,20 +83,16 @@ class LogsInterceptors extends InterceptorsWrapper {
9783 @override
9884 onError (DioException err, handler) async {
9985 if (Config .DEBUG ! ) {
100- if (kDebugMode) {
101- print ('请求异常: $err ' );
102- print ('请求异常信息: ${err .response ?.toString () ?? "" }' );
103- }
86+ printLog ('请求异常: $err ' );
87+ printLog ('请求异常信息: ${err .response ?.toString () ?? "" }' );
10488 }
10589 try {
10690 addLogic (sHttpErrorUrl, err.requestOptions.path);
10791 var errors = < String , dynamic > {};
10892 errors["error" ] = err.message;
10993 addLogic (sHttpError, errors);
11094 } catch (e) {
111- if (kDebugMode) {
112- print (e);
113- }
95+ printLog (e);
11496 }
11597 return super .onError (err, handler);
11698 }
0 commit comments