onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
if (!NetworkLoggerConfig.isEnabled) {
debugPrint('⚠️ CoteNetworkLogger: Logger is disabled');
handler.next(options);
return;
}
try {
final transactionId = _generateTransactionId(options);
_requestTransactionIds[options] = transactionId;
NetworkLogStore.instance.upsertLog(transactionId, {
'transactionId': transactionId,
'type': 'request',
'method': options.method,
'url': options.uri.toString(),
'headers': options.headers,
'body': options.data,
'timestamp': DateTime.now().toIso8601String(),
'status': 'pending',
});
debugPrint('✅ CoteNetworkLogger: Intercepted request: ${options.uri} (transactionId: $transactionId)');
handler.next(options);
} catch (e) {
debugPrint('❌ CoteNetworkLogger: Failed to log request: $e');
handler.next(options);
}
}