The Messenger of Allah ﷺ said, "No believer is pricked by a thorn or anything greater than that without Allah raising him a degree by it and erasing one of his sins through it."
حدثنا هناد حدثنا أبو معاوية عن الأعمش عن إبراهيم عن الأسود
قال رسول الله ﷺ لا يصيب المؤمن شوكة فما فوقها إلا رفعه الله بها درجة وحط عنه بها خطيئة
Reference: Also reported by Muslim, Chapter on Righteousness and Kinship Ties, Section on the reward of the believer for the illness that befalls him, etc., hadith no. 2572, from the hadith of Abu Muawiya Adarir, with the same wording.On this topic, there are also reports from Saad bin Abu Waqqas [to come: 2398], Abu Ubayda bin Jarra [Ahmad: 1/196 and Darimi, hadith no. 2766], Abu Hurairah [to come: 2088], Abu Umama [Ibn Majah, hadith no. 1597], Abu Saeed [to come: 966], Anas [Bukhari, hadith no. 5653], Abdullah bin Amr [Ahmad: 2/159, 194, 198 and Bukhari in Adab al-Mufrad, hadith no. 500], Asad bin Kurz [Abdullah bin Ahmad in the additions to the Musnad: 4/70], Jabir [Ahmad: 3/349, 386, 400 and Bukhari in Adab al-Mufrad, hadith no. 508], Abdul-Rahman bin Azhar [Hakim: 3/431], and Abu Musa [to come: 3252].