The first clause is what you were in the middle of, and 걸리다 is being caught at it: sneaking a chocolate baguette, cheating on a partner, ordering a burger, gaming, smoking, using a VPN, running off with something. It always carries the flavour of doing something you were not supposed to be doing. The fuller spelling 다가 걸리다 is the same expression with nothing added.