The Prophet ﷺ said, "None of you should wish for death because of some harm that has befallen him. Rather, let him say, 'O Allah, keep me alive as long as life is better for me, and take me when death is better for me.'"
حدثنا عفان أخبرنا حماد عن ثابت
أن النبي ﷺ قال لا يتمنين أحدكم الموت من ضر أصابه ولكن ليقل اللهم أحيني ما كانت الحياة خيرا لي وتوفني إذا كانت الوفاة خيرا لي