Make sure to keep the Mac and the connected hard drive on a solid, stable, flat surface like a table. This will prevent unnecessary tug that disconnects them. Also, use a single cable instead of several cables to connect the drive to the Mac. Finally, get a reputed USB-C hub if you use newer MacBooks.