Skip to main content
Published: June 11 2004, 4:59:00 PMUpdated: November 28 2020, 1:04:46 PM

Error: Code 502: Bad Gateway error was encountered

Q: I am getting an HTML error much like this:


Proxy Error
The proxy server could not handle the request POST /api.html.
Reason: Error reading from remote server


Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.27 Server at thrust.sjc.ebay.com Port 8080

What do I do and what can I do to keep my XML Parser from crashing?

A: We apologize for this non XML-Type error message.
What we suggest is that you do one of the following things:
1) Check the content type of the result or the HTTP status code of the result for every API call. If the content-type is not XML or if the status code is not 200, then the content is almost always HTML or empty and you should access the result as a string and process the result as an HTML string.
OR
2) Attempt to load the result into an XML parser and check the ErrorCode returned by the parser before trying to access any part of the DOM Document. If the parser could not load the result, then access the result as a string and process the result as an HTML string.

In any case, this 502 error message should be treated like a special form of an XML SystemError message. Attempt 2 retries and if both fail, then wait 30 seconds (this wait period can be less if your application load cannot afford idle time, in such cases continuous retries is acceptable) and make a set of 3 retries again. Follow this "algorithm" until the call returns a satisfactory response.

How well did this answer your question?