onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) async {
try {
final networkRequest = NetworkRequest(
method: options.method,
path: options.path,
headers: Map<String, String>.from(
options.headers.cast<String, String>(),
),
queryParameters: options.queryParameters,
body: options.data,
);
await interceptor.onRequest(networkRequest);
// Apply any changes back to the request options
options.headers.clear();
options.headers.addAll(networkRequest.headers);
options.queryParameters.clear();
options.queryParameters.addAll(networkRequest.queryParameters ?? {});
options.data = networkRequest.body;
handler.next(options);
} catch (e) {
handler.reject(
DioException(
requestOptions: options,
error: e,
message: 'Interceptor error: ${e.toString()}',
),
);
}
}