11// ignore_for_file: type_literal_in_constant_pattern
22
33import 'package:dio/dio.dart' ;
4+ import 'package:flutter/foundation.dart' ;
45import 'package:gsy_github_app_flutter/common/config/config.dart' ;
56
67/// Log 拦截器
@@ -19,16 +20,22 @@ class LogsInterceptors extends InterceptorsWrapper {
1920 @override
2021 onRequest (RequestOptions options, handler) async {
2122 if (Config .DEBUG ! ) {
22- print ("请求url:${options .path } ${options .method }" );
23+ if (kDebugMode) {
24+ print ("请求url:${options .path } ${options .method }" );
25+ }
2326 options.headers.forEach ((k, v) => options.headers[k] = v ?? "" );
24- print ('请求头: ${options .headers }' );
27+ if (kDebugMode) {
28+ print ('请求头: ${options .headers }' );
29+ }
2530 if (options.data != null ) {
26- print ('请求参数: ${options .data }' );
31+ if (kDebugMode) {
32+ print ('请求参数: ${options .data }' );
33+ }
2734 }
2835 }
2936 try {
3037 addLogic (sRequestHttpUrl, options.path);
31- var data;
38+ dynamic data;
3239 if (options.data is Map ) {
3340 data = options.data;
3441 } else {
@@ -42,15 +49,19 @@ class LogsInterceptors extends InterceptorsWrapper {
4249 }
4350 addLogic (sHttpRequest, map);
4451 } catch (e) {
45- print (e);
52+ if (kDebugMode) {
53+ print (e);
54+ }
4655 }
4756 return super .onRequest (options, handler);
4857 }
4958
5059 @override
5160 onResponse (Response response, handler) async {
5261 if (Config .DEBUG ! ) {
53- print ('返回参数: $response ' );
62+ if (kDebugMode) {
63+ print ('返回参数: $response ' );
64+ }
5465 }
5566 switch (response.data.runtimeType) {
5667 case Map || List :
@@ -61,7 +72,9 @@ class LogsInterceptors extends InterceptorsWrapper {
6172 addLogic (sResponsesHttpUrl, response.requestOptions.uri.toString ());
6273 addLogic (sHttpResponses, data);
6374 } catch (e) {
64- print (e);
75+ if (kDebugMode) {
76+ print (e);
77+ }
6578 }
6679 }
6780 case String :
@@ -72,7 +85,9 @@ class LogsInterceptors extends InterceptorsWrapper {
7285 addLogic (sResponsesHttpUrl, response.requestOptions.uri.toString ());
7386 addLogic (sHttpResponses, data);
7487 } catch (e) {
75- print (e);
88+ if (kDebugMode) {
89+ print (e);
90+ }
7691 }
7792 }
7893 }
@@ -82,16 +97,20 @@ class LogsInterceptors extends InterceptorsWrapper {
8297 @override
8398 onError (DioException err, handler) async {
8499 if (Config .DEBUG ! ) {
85- print ('请求异常: $err ' );
86- print ('请求异常信息: ${err .response ?.toString () ?? "" }' );
100+ if (kDebugMode) {
101+ print ('请求异常: $err ' );
102+ print ('请求异常信息: ${err .response ?.toString () ?? "" }' );
103+ }
87104 }
88105 try {
89106 addLogic (sHttpErrorUrl, err.requestOptions.path);
90107 var errors = < String , dynamic > {};
91108 errors["error" ] = err.message;
92109 addLogic (sHttpError, errors);
93110 } catch (e) {
94- print (e);
111+ if (kDebugMode) {
112+ print (e);
113+ }
95114 }
96115 return super .onError (err, handler);
97116 }
0 commit comments