In Isaiah 38, King Hezekiah became deathly ill and received a message from God that he would die.

When Hezekiah cried out to God, He healed Hezekiah and added 15 years to his life.

What the king said next was very interesting:
But what can I say? He has spoken to me, and he himself has done this. I will walk humbly all my years because of this anguish of my soul. Surely it was for my benefit that I suffered such anguish. In your love you kept me from the pit of destruction; you have put all my sins behind your back. (‭‭Isaiah‬ ‭38:15, 17‬ ‭NIV‬‬)

At times God uses the bad things that happen to humble us and grow us spiritually.

Don’t despise your trials. Allow God to complete His great work in you!

‭‭James‬ ‭1:2, 4‬ ‭NIV‬‬
Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, Let perseverance finish its work so that you may be mature and complete, not lacking anything.