onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
if (!NetworkLoggerConfig.isEnabled) {
handler.next(options);
return;
}
try {
final transactionId = _generateTransactionId(options);
_requestTransactionIds[options] = transactionId;
final timestamp = DateTime.now().toIso8601String();
NetworkLogStore.instance.upsertLog(transactionId, {
'transactionId': transactionId,
'type': 'request',
'method': options.method,
'url': options.uri.toString(),
'headers': options.headers,
'requestHeaders': Map<String, dynamic>.from(options.headers),
'requestTimestamp': timestamp,
'requestBody': options.data,
'timestamp': timestamp,
'status': 'pending',
});
handler.next(options);
} catch (e) {
if (kDebugMode) {
debugPrint('❌ CoteNetworkLogger: Failed to log request: $e');
}
handler.next(options);
}
}