wrapIdentifyException function
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,
);
}