I´ve been having that problem since a long time and the advice that I can give you is don´t panic and keep going.
It actually happened a few days ago that I lost my erection during sex and I just kept kissing the girl made her grab my penis untill it got hard again and that´s it. I guess sometimes we guys just get nervous or distracted by something and we can lose some of our erection, but you just have to relax and keep doing what turns you on untill you get it back. Stoping will kill the passion and will make you feel like crap and that´ll make it harder to get the erection back.
It´s a shitty problem to have actually but you can overcome it specially if you have a constant girlfriend and you get confortable with her. Just when you are kissing at the beggining and it gets hard put the condom on and if in that lapse of time you lose it just keep touching her vagina ( or whatever you like to touch) and kissing and you´ll get it back again and then just go quick and penetrate.
If it helped dont hesitate on writing it here
g luck