Is it appropriate to return HTTP 504 Gateway Timeout as a response if a database server times out?

StackOverflow https://stackoverflow.com/questions/21223228

سؤال

In a REST service, is returning a 504 status code appropriate when the application times out waiting for a database query and is unable to complete the client's request?

504 Gateway Timeout

The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.


Currently we're just showing a generic 500 error, which gets displayed in a UI as a generic server error. There is some utility in showing to the user that it is a database timeout error (perhaps along with suggestions to reduce the scope of what they're asking for), because at the least they're armed with more useful information if they contact whoever is responsible for their server.


Any pointers to how other REST services handle a database timeout?

هل كانت مفيدة؟

المحلول

I would return 500 as well, with details in the payload indicating what went wrong. This is the description for 504 from RFC 2616:

The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.

That error description for 504 indicates that the server is acting as a gateway or proxy, which your service is definitely not doing.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top