wrapIdentifyException function

IdentifyException wrapIdentifyException({
  1. required PeerId peerId,
  2. required Object exception,
  3. Duration? timeout,
})

Helper function to wrap a generic exception into an appropriate IdentifyException subtype.

This is useful for converting exceptions caught during identify operations into properly typed exceptions.

Implementation

IdentifyException wrapIdentifyException({
  required PeerId peerId,
  required Object exception,
  Duration? timeout,
}) {
  if (isTimeoutException(exception)) {
    return IdentifyTimeoutException.fromException(
      peerId: peerId,
      exception: exception,
      timeout: timeout,
    );
  }

  // For now, wrap unknown exceptions as stream exceptions
  return IdentifyStreamException(
    peerId: peerId,
    message: 'Identify stream error for peer $peerId',
    cause: exception,
  );
}