Well, it's mostly beyond your control. A 502 usually indicates there's something wrong with a website's server, or the way a website's servers communicate with each other. Another reason is also because there's something wrong with your service provider.
In most cases, the 502 should go away after a few hours. If you're into technical terms, you can check this out for more details: http://www.checkupdown.com/status/E502.html