Hi Alexo,
502 gateway errors are one of the more common network errors with modern distributed server systems, it means that one server got a bad response from another, i.e. an edge server to a central server. Usually a sign of a transient infrastructure outage.
Your code should gracefully handle the error, perhaps making a log fie entry and informing the user of the issue and it’s temporary nature and then implement a exponential back off and retry system where you wait twice as long as the last time each time you retry.
Build in some reasonable maximum wait period and allow the user to manually retry if that seems appropriate.