They are both errors with the gateway, although a 502 Error indicates that the upstream server provided an invalid response to the gateway. A 504 is when the gateway did not get any response whatsoever and then went dead. The 504 Gateway Time-Out (https://datarecovee.com/504-error/) is a 504 actually, not a corrupted response.