I am writing a wrapper over a Third party API.
If I don't get response for certain time I throw the gateway timeout exception.
But i can see there is one more HttpStatus.REQUEST_TIMEOUT other than HttpStatus.GATEWAY_TIMEOUT
I don't know which one to use and when.
Any help is appreciated.
The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.
The HyperText Transfer Protocol (HTTP) 504 Gateway Timeout server error response code indicates that the server, while acting as a gateway or proxy, did not get a response in time from the upstream server that it needed in order to complete the request.
The 504 “Gateway Timeout” Error indicates that the browser sent an HTTP request to the server and it did not receive a response in time from another server to complete the request. In most cases, you can resolve it by refreshing the web page.
The HyperText Transfer Protocol (HTTP) 408 Request Timeout response status code means that the server would like to shut down this unused connection. It is sent on an idle connection by some servers, even without any previous request by the client.
Request timeouts are useful for preventing a poor user experience, especially if there's an alternative that we can default to when a resource is taking too long.
Once your server is acting as a gateway or proxy of an upstream server, you should use 504
to indicate that the connection has timed out. See how this status code is defined:
6.6.5. 504 Gateway Timeout
The
504
(Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.
The 408
status code has a completed different meaning and indicates that the server would like to shut down an unused connection with the client:
6.5.7. 408 Request Timeout
The
408
(Request Timeout) status code indicates that the server did not receive a complete request message within the time that it was prepared to wait. A server SHOULD send the "close" connection option in the response, since408
implies that the server has decided to close the connection rather than continue waiting. If the client has an outstanding request in transit, the client MAY repeat that request on a new connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With