Start with this Du'a
When something goes wrong: Qadaru-llahi wa ma sha'a fa'al
قَدَرُ اللَّهِ وَمَا شَاءَ فَعَلَ
Qadaru-llahi wa ma sha'a fa'al
“This is the decree of Allah, and He does whatever He wills.”
Sahih Muslim 2664
Do not say 'if only I had done such and such', for 'if only' opens the door to the work of Shaytan.