The Bible tells us a lot about affliction and the book of Psalms is an expert talking about these issues. David went through many tribulations, many times he felt abandoned by God, but he knew that God in whom he believed never departed from him and in the same way we have to believe that God accompanies us in all our tribulations and that when we see that He is far away is when He is closest to us.
The psalmist said:
19 The righteous person may have many troubles,
but the Lord delivers him from them all;
20 he protects all his bones,
not one of them will be broken.
21 Evil will slay the wicked;
the foes of the righteous will be condemned.
22 The Lord will rescue his servants;
no one who takes refuge in him will be condemned.