safeRedact method

Object safeRedact(
  1. Object data, {
  2. required bool useRedaction,
})
inherited

Applies redaction with error handling: logs a warning and returns a placeholder on failure instead of propagating the exception.

Implementation

Object safeRedact(Object data, {required bool useRedaction}) {
  try {
    return _payload.body(
          data,
          enableRedaction: useRedaction,
          normalizer: NetworkPayloadSanitizer.encodeJsonGracefully,
        ) ??
        data;
  } catch (e, s) {
    logger.logData(
      ISpectLogData(
        'Redaction failed, data omitted: $e',
        logLevel: LogLevel.warning,
        stackTrace: s,
      ),
    );
    return ph.redactionFailedPlaceholder;
  }
}