Praise be to Allah,
Ismaa’eel ibn Ibraaheem narrated to us from ‘Abd-ul-‘Azeez ibn Shuhayb from Anas ibn Maalik who said,
“The Messenger of Allah (peace and blessings be on him) said, ‘No one of you should wish for death as a result of any harm that may have afflicted him. If he must wish for it, then let him say: Allaahumma ahyinee maa kaanat-il-hayaatu khayran lee, wa tawaffanee idhaa kaanat-il-wajaatu khayran lee (0 Allah, let me live so long as life is better for me, or cause me to die if death is better for me).'”
(Musnad Ahmad, Vol. 3, p. 101. The isnaad of this Hadeeth is Saheeh according to the conditions set by al-Bukhaaree and Muslim.)
Note: Here harm could be anything that causes pain, discomfort, uneasiness such as poverty, persecution, or disease.
Source:
Thulaathiyyaat Musnad Ahmad ibn Hanbal (may Allah have mercy on him)
Reports of Imaam Ahmad that have only three narrators between him and the Prophet, peace, and blessings be upon him.
Shaykh Muhammad ibn Ahmad ibn Saalim as–Saffaareenee al–Hanbalee ~(1114 –1188 AH)