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,
) {
if (level == Level.none) return handler.next(options);
logPrint('[DIO]--> ${options.method} ${options.uri}');
if (level == Level.basic) return handler.next(options);
options.headers.forEach((key, value) {
logPrint('[DIO][HEADER]$key:$value');
});
if (level == Level.headers) {
logPrint('[DIO]--> END ${options.method}');
return handler.next(options);
}
final data = options.data;
if (data != null) {
// logPrint('[DIO]dataType:${data.runtimeType}');
if (data is Map) {
if (compact) {
logPrint('[DIO][DATA]$data');
} else {
_prettyPrintJson(data);
}
} else if (data is FormData) {
// NOT IMPLEMENT
} else {
logPrint('[DIO][DATA]${data.toString()}');
}
}
logPrint('[DIO]--> END ${options.method}');
return handler.next(options);
}