That’s the hardest thing ever, and I haven’t yet heard a good response.
If we try to be mindful of lashon hara, and the person needing support is venting about someone, it doesn’t help if we say, “Well, maybe the person was just going through a hard time” or otherwise try to rationalize the behavior that bothered the friend. Efforts like that to steer the conversation away from lashon hara tend not to work, and it makes us look unsupportive, or taking the wrong side.
I think halachically we’re not even supposed to hear lashon hara. Should we say, “I can’t hear this” and try to interrupt the conversation to avoid hearing lashon hara? Then what about our friend in need? If we explain why we’re doing that, then we appear judgy. And probably hypocritical since I’m sure we’ve been in positions where we said lashon hara ourselves.
Maybe the best thing is to just say things like, “That sounds tough.” and leave it at that. Technically we are allowing ourselves to listen to lashon hara and are tacitly supporting the friend in relating lashon hara. But it could be a middle ground. Maybe we can subtly give the message that we’re not actively participating in the lashon hara, but we are supporting what our friend is going through.