onRequest method
The callback will be executed before the request is initiated.
If you want to continue the request, call handler.next
.
If you want to complete the request with some custom data,
you can resolve a Response
object with handler.resolve
.
If you want to complete the request with an error message,
you can reject a DioError
object with handler.reject
.
Implementation
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final data = options.data;
if (data != null) {
final formData = data as dio.FormData;
final formMap = <String, dynamic>{};
formMap.addEntries(formData.fields);
formMap.addEntries(formData.files);
log(jsonEncode(formMap),
time: DateTime.now(), name: "Requesting => ${options.path}");
} else {
log(options.method,
time: DateTime.now(), name: "Requesting => ${options.path}");
}
return super.onRequest(options, handler);
}