|
1 | 1 | import 'package:dio/dio.dart'; |
| 2 | +import 'package:flutter/foundation.dart'; |
2 | 3 |
|
3 | 4 | class PrinterInterceptor extends Interceptor { |
4 | 5 |
|
5 | 6 | @override |
6 | 7 | Future onRequest(RequestOptions options, RequestInterceptorHandler handler) async { |
7 | | - print('''------------------- START REQUEST |
| 8 | + if (kDebugMode) print('''-------------------> HTTP REQUEST |
8 | 9 | Method: ${options.method} |
9 | 10 | Headers: ${options.headers} |
10 | 11 | Path: ${options.baseUrl}${options.path} |
11 | 12 | Query parameters: ${options.queryParameters} |
12 | 13 | Data: ${options.data} |
13 | 14 | Content type: ${options.contentType} |
14 | | -------------------- END HTTP REQUEST'''); |
| 15 | +-------------------> END HTTP REQUEST'''); |
15 | 16 | return super.onRequest(options, handler); |
16 | 17 | } |
17 | 18 |
|
18 | 19 | @override |
19 | 20 | Future onResponse(Response response, ResponseInterceptorHandler handler) async { |
20 | | - print('''------------------- START RESPONSE |
| 21 | + if (kDebugMode) print('''<------------------- HTTP RESPONSE |
21 | 22 | Status code: ${response.statusCode} |
| 23 | +Headers: ${response.headers} |
22 | 24 | Response data: ${response.data} |
23 | 25 | Path: ${response.realUri} |
24 | | -------------------- END RESPONSE'''); |
25 | | - super.onResponse(response, handler);//Headers: ${response.headers} |
| 26 | +<------------------- END HTTP RESPONSE'''); |
| 27 | + super.onResponse(response, handler); |
26 | 28 | } |
27 | 29 |
|
28 | 30 | @override |
29 | 31 | void onError(DioError err, ErrorInterceptorHandler handler) async { |
30 | | - print('''------------------- START ERROR |
| 32 | + if (kDebugMode) print('''<------------------- HTTP ERROR |
| 33 | +Headers: ${err.response?.headers.map ?? {}} |
31 | 34 | Response: ${err.response} |
32 | 35 | Error type: ${err.type} |
33 | 36 | Error message: ${err.message} |
34 | 37 | Path: ${err.response?.realUri} |
35 | | -------------------- END ERROR'''); |
| 38 | +<------------------- END HTTP ERROR'''); |
36 | 39 | super.onError(err, handler); |
37 | 40 | } |
38 | 41 | } |
0 commit comments