Narrated Anas: Allah's Messenger ﷺ said," None of you should long for death because of a calamity that had befallen him, and if he cannot, but long for death, then he should say, 'O Allah! Let me live as long as life is better for me, and take my life if death is better for me'. "
This hadith also teaches us about the importance of having good intentions when making du'a or prayers - even when asking for something seemingly negative like an early death, we must still have faith in Allah's wisdom and ask Him only what is best for ourselves. It reminds us that ultimately, our lives are in His hands and He knows what will bring about the most benefit in this world and the hereafter.