Sunan Abi Dawud, Hadith 3102

Narrated Anas: The Messenger of Allah as saying: No one of you should wish for death for any calamity that befalls him, but he should say: O Allah! cause me to live so long as my life is better for me ; and cause me to die where death is better for me.

حَدَّثَنَا بِشْرُ بْنُ هِلاَلٍ، حَدَّثَنَا عَبْدُ الْوَارِثِ، عَنْ عَبْدِ الْعَزِيزِ بْنِ صُهَيْبٍ، عَنْ أَنَسِ بْنِ مَالِكٍ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ لاَ يَدْعُوَنَّ أَحَدُكُمْ بِالْمَوْتِ لِضُرٍّ نَزَلَ بِهِ وَلَكِنْ لِيَقُلِ اللَّهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي ‏" ‏ ‏.‏

sunnah.com

also referenced under: Hadith 3108 (DarusSalam)