onRequest method

  1. @override
void onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)

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;
    NetworkLogStore.instance.upsertLog(transactionId, {
      'transactionId': transactionId,
      'type': 'request',
      'method': options.method,
      'url': options.uri.toString(),
      'headers': options.headers,
      'requestBody': options.data,
      'timestamp': DateTime.now().toIso8601String(),
      'status': 'pending',
    });
    handler.next(options);
  } catch (e) {
    if (kDebugMode) debugPrint('❌ CoteNetworkLogger: Failed to log request: $e');
    handler.next(options);
  }
}