Skip to content

Commit b3ccb34

Browse files
committed
Interceptor print
1 parent 11f08ed commit b3ccb34

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

lib/api/interceptor_logger.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
import 'package:dio/dio.dart';
2+
import 'package:flutter/foundation.dart';
23

34
class PrinterInterceptor extends Interceptor {
45

56
@override
67
Future onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
7-
print('''------------------- START REQUEST
8+
if (kDebugMode) print('''-------------------> HTTP REQUEST
89
Method: ${options.method}
910
Headers: ${options.headers}
1011
Path: ${options.baseUrl}${options.path}
1112
Query parameters: ${options.queryParameters}
1213
Data: ${options.data}
1314
Content type: ${options.contentType}
14-
------------------- END HTTP REQUEST''');
15+
-------------------> END HTTP REQUEST''');
1516
return super.onRequest(options, handler);
1617
}
1718

1819
@override
1920
Future onResponse(Response response, ResponseInterceptorHandler handler) async {
20-
print('''------------------- START RESPONSE
21+
if (kDebugMode) print('''<------------------- HTTP RESPONSE
2122
Status code: ${response.statusCode}
23+
Headers: ${response.headers}
2224
Response data: ${response.data}
2325
Path: ${response.realUri}
24-
------------------- END RESPONSE''');
25-
super.onResponse(response, handler);//Headers: ${response.headers}
26+
<------------------- END HTTP RESPONSE''');
27+
super.onResponse(response, handler);
2628
}
2729

2830
@override
2931
void onError(DioError err, ErrorInterceptorHandler handler) async {
30-
print('''------------------- START ERROR
32+
if (kDebugMode) print('''<------------------- HTTP ERROR
33+
Headers: ${err.response?.headers.map ?? {}}
3134
Response: ${err.response}
3235
Error type: ${err.type}
3336
Error message: ${err.message}
3437
Path: ${err.response?.realUri}
35-
------------------- END ERROR''');
38+
<------------------- END HTTP ERROR''');
3639
super.onError(err, handler);
3740
}
3841
}

0 commit comments

Comments
 (0)