Welcome To Golang By Example

Server Error – 500 vs 502 vs 503 vs 504

Overview

All 5XX errors are server errors. In this article, we will learn about the difference between all of them.

In this article, we use the term proxy/gateway server. Some of the examples of proxy/gateway server are:

500 (Internal Server Error)

500 means Internal Server Error.  A service can raise a 500 in the case in which it ran into an error that was unexpected. Since 500 is purely a server error, it is meant to be retried by the client

Some of the cases:

How to resolve:

502 (Bad Gateway Error)

502  means that the proxy/gateway server in between the origin server and the client got an unexpected response from the origin server.  Do notice that in this case proxy/gateway server did get a response but an expected one. An example of an unexpected response could be that proxy/gateway server was expecting a JSON but instead got an HTML. It can happen in the below case

Some of the cases:

How to resolve:

503 (Service Unavailable )

503 means that the server is at capacity and it is not able to handle more request or it could also mean that the server is unavailable right now because it is under maintenance. It is generally a temporary state. Some of the cases can be

Some of the cases:

How to resolve

504(Gateway Timeout)

504 means that the proxy server or gateway did not receive a response from the origin server within a specified timeout. Consider for example that an Elastic Load Balancer is sitting between your origin server, and the ELB timed out trying to receiving the response from your server. Some cases can be

Some of the cases:

How to resolve