2 Corinthians 1:9:
Indeed, we felt that we had received the sentence of death. But that was to make us rely not on ourselves but on God who raises the dead.
Adversity by its very nature is the removal of things on which our comfort and hope have rested and so it will either result in anger toward God or greater reliance on him alone for our peace.
And his purpose for us in adversity is not that we get angry or discouraged, but that our hope shift off earthly things onto God.
God’s main purpose in all adversity is to make us stop trusting in ourselves or any man.