We were with Messenger of Allah ﷺ when the sun eclipsed. Messenger of Allah ﷺ stood up dragging his cloak till he entered the Mosque. He led us in a two-rakʿat prayer till the sun (eclipse) had cleared. Then the Prophet ﷺ said, "The sun and the moon do not eclipse because of someone's death. So whenever you see these eclipses pray and invoke (Allah) till the eclipse is over."
كُنَّا عِنْدَ رَسُولِ اللَّهِ ﷺ فَانْكَسَفَتِ الشَّمْسُ فَقَامَ النَّبِيُّ ﷺ يَجُرُّ رِدَاءَهُ حَتَّى دَخَلَ الْمَسْجِدَ فَدَخَلْنَا فَصَلَّى بِنَا رَكْعَتَيْنِ حَتَّى انْجَلَتِ الشَّمْسُ فَقَالَ ﷺ إِنَّ الشَّمْسَ وَالْقَمَرَ لاَ يَنْكَسِفَانِ لِمَوْتِ أَحَدٍ فَإِذَا رَأَيْتُمُوهُمَا فَصَلُّوا وَادْعُوا حَتَّى يُكْشَفَ مَا بِكُمْ