It will depend on your relationship with the person how personal you make this message.
I would advise NOT saying how it could have been worse. That minimizes what the person is experiencing.
"I'm so sorry to hear that" is an appropriate response to most types of bad news.
"I'm so very sorry for your loss" is an appropriate response to news of a death.
"I wish you a speedy recovery" is appropriate when responding to news of injury or illness.
Recently, a colleague had an adoption fall through. I said honestly to her "I wish I could think of something to say to make you feel better. All I can say is I cried for you when I heard and I'm so, so sorry, and I'm here if you need to talk about it." Sometimes, you can't console, but you can show you care.
Student or Learner