|
@@ -28,56 +28,12 @@ class PrettyLogInterceptor extends Interceptor {
|
|
/// Print error message
|
|
/// Print error message
|
|
bool error;
|
|
bool error;
|
|
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Future onRequest(RequestOptions options) async {
|
|
|
|
- _printRequest(options);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Future onError(DioError err) async {
|
|
|
|
- if (error) {
|
|
|
|
- print('*** DioError ***:');
|
|
|
|
- print('uri: ${err.request.uri}');
|
|
|
|
- print('$err');
|
|
|
|
- if (err.response != null) {
|
|
|
|
- _printResponse(err.response);
|
|
|
|
- }
|
|
|
|
- print('');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void _printRequest(RequestOptions options) async {
|
|
|
|
- print('*** Request ***');
|
|
|
|
- _printKV('uri', options.uri);
|
|
|
|
-
|
|
|
|
- if (request) {
|
|
|
|
- _printKV('method', options.method);
|
|
|
|
- _printKV('responseType', options.responseType?.toString());
|
|
|
|
- _printKV('followRedirects', options.followRedirects);
|
|
|
|
- _printKV('connectTimeout', options.connectTimeout);
|
|
|
|
- _printKV('receiveTimeout', options.receiveTimeout);
|
|
|
|
- _printKV('extra', options.extra);
|
|
|
|
- }
|
|
|
|
- if (requestHeader) {
|
|
|
|
- print('headers:');
|
|
|
|
- options.headers.forEach((key, v) => _printKV(' $key', v));
|
|
|
|
- }
|
|
|
|
- if (requestBody) {
|
|
|
|
- print('data:');
|
|
|
|
- _printAll(options.data);
|
|
|
|
- }
|
|
|
|
- print('');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Future onResponse(Response response) async {
|
|
|
|
- print('*** Response ***');
|
|
|
|
- _printResponse(response);
|
|
|
|
|
|
+ void _printKV(String key, Object v) {
|
|
|
|
+ print('$key: $v');
|
|
}
|
|
}
|
|
|
|
|
|
void _printResponse(Response response) {
|
|
void _printResponse(Response response) {
|
|
- _printKV('uri', response.request?.uri);
|
|
|
|
|
|
+ _printKV('uri', response.requestOptions.uri);
|
|
if (responseHeader) {
|
|
if (responseHeader) {
|
|
_printKV('statusCode', response.statusCode);
|
|
_printKV('statusCode', response.statusCode);
|
|
if (response.isRedirect == true) {
|
|
if (response.isRedirect == true) {
|
|
@@ -95,11 +51,55 @@ class PrettyLogInterceptor extends Interceptor {
|
|
print('');
|
|
print('');
|
|
}
|
|
}
|
|
|
|
|
|
- void _printKV(String key, Object v) {
|
|
|
|
- print('$key: $v');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void _printAll(msg) {
|
|
void _printAll(msg) {
|
|
msg.toString().split('\n').forEach(print);
|
|
msg.toString().split('\n').forEach(print);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
|
|
|
+ super.onRequest(options, handler);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void onError(DioException err, ErrorInterceptorHandler handler) {
|
|
|
|
+ super.onError(err, handler);
|
|
|
|
+ if (error) {
|
|
|
|
+ print('*** DioError ***:');
|
|
|
|
+ print('uri: ${err.requestOptions.uri}');
|
|
|
|
+ print('$err');
|
|
|
|
+ if (err.response != null) {
|
|
|
|
+ _printResponse(err.response);
|
|
|
|
+ }
|
|
|
|
+ print('');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void _printRequest(RequestOptions options) async {
|
|
|
|
+ print('*** Request ***');
|
|
|
|
+ _printKV('uri', options.uri);
|
|
|
|
+
|
|
|
|
+ if (request) {
|
|
|
|
+ _printKV('method', options.method);
|
|
|
|
+ _printKV('responseType', options.responseType?.toString());
|
|
|
|
+ _printKV('followRedirects', options.followRedirects);
|
|
|
|
+ _printKV('connectTimeout', options.connectTimeout);
|
|
|
|
+ _printKV('receiveTimeout', options.receiveTimeout);
|
|
|
|
+ _printKV('extra', options.extra);
|
|
|
|
+ }
|
|
|
|
+ if (requestHeader) {
|
|
|
|
+ print('headers:');
|
|
|
|
+ options.headers.forEach((key, v) => _printKV(' $key', v));
|
|
|
|
+ }
|
|
|
|
+ if (requestBody) {
|
|
|
|
+ print('data:');
|
|
|
|
+ _printAll(options.data);
|
|
|
|
+ }
|
|
|
|
+ print('');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ Future onResponse(Response response) async {
|
|
|
|
+ print('*** Response ***');
|
|
|
|
+ _printResponse(response);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|