initInterceptors method
void
initInterceptors()
Implementation
void initInterceptors() {
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) {
if (debugMode) {
printWrapped('*' * 10);
if (options.data != null) printWrapped(options.data.toString());
if (options.queryParameters.isNotEmpty) {
printWrapped(options.queryParameters.toString());
}
printWrapped(options.headers.toString());
printWrapped('${options.method} ${options.path}');
}
if (options.data != null) {
options.data =
FormData.fromMap(options.data as Map<String, dynamic>);
}
// Do something before request is sent
return handler.next(options); //continue
},
onResponse: (response, handler) {
if (debugMode) {
printWrapped(response.data.toString());
printWrapped(
'${response.statusCode} ${response.requestOptions.method} ${response.requestOptions.path}',
);
printWrapped('*' * 10);
}
// Do something with response data
return handler.next(response); // continue
},
onError: (DioError e, handler) {
if (debugMode) {
printWrapped(
'ERROR[${e.response?.statusCode}] => PATH: ${e.requestOptions.path}',
);
printWrapped('*' * 10);
}
// Do something with response error
return handler.next(e); //continue
},
),
);
}