Ibn Jawzi says,
If you fall into a hardship that is hard to be free from, you can’t (do anything) but make du’a and take refuge in Allāh, after repenting from sins, because sinning necessitates punishment, so if it is erased with repentance, the reason (for punishment) is lifted. So if you repented and made du’a, and did not see any trace of response, then look into your affair. Maybe the repentance was not sound, so correct it then make du’a and don’t become tired of making du’a. Maybe the good is in delaying the response, and maybe the good is not in responding, so you will be rewarded and responded to according to what benefits you, and it would be beneficial for you to not be given what you requested, but rather to be given other than it as a replacement. So if Iblees comes and says: ‘How much did you call upon Him and did not see any response?’ Then say: ‘I worship (Allāh) by making du’a, and I am certain that the answer will come. But maybe its delay is due to some good, and even if it doesn’t happen, worship and humility takes place.’ So take care not to ask for something except by combining it with asking for that which is good, because the occurrence of many a wish from the dunya was a cause for destruction.
Reference : Sayd ul-Khatir