Is 502 an appropriate status code for a database error?

No, I don’t think an HTTP 502 Bad Gateway error is appropriate when a database error occurs. HTTP errors say something about the HTTP protocol. This specific error indicates a server is trying to relay the HTTP request, but the upstream server did not respond correctly. Your web application communicating with a database server is … Read more

Is HTTP status 422 appropriate for records that fail uniqueness validation?

NB: tried to do a detailed answer below poke’s one, but it doesn’t seem to be possible, so I will answer here. I think using 422 for validation errors is fine. The Webdav RFC doesn’t say 422 means “semantic errors”, it says the server was “unable to process the contained instructions” (see https://www.rfc-editor.org/rfc/rfc4918#section-11.2). “Semantic errors” … Read more

HTTP status code when single request asks for too large resource or too many of them

403 sounds like the most appropriate choice. It basically says “nu-uh. You don’t get to see that.”, which is pretty much the case here. 10.4.4 403 Forbidden The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. […] Of course, it’d be a … Read more

Which HTTP status code to return when the DELETE operation is not allowed for particular reason

I would go with 409: Conflict, because what you have is a violation of resource state. 405: Method Not Allowed would also work. If you’d want to use a 405, you’d have to send an Allow header to indicate the supported methods, and the supported methods would vary depeding on the resource’s state. In my … Read more

can’t get response status code with JavaScript fetch [duplicate]

The status code is the status property on the response object. Also, unless you’re using JSON with your error responses (which some people do, of course), you need to check the status code (or the ok flag) before calling json: fetch(`${baseUrl}api/user/login`, { credentials: “include”, // ยน See note below headers: myHeaders }) .then(function(response) { console.log(response.status); … Read more

How to use HTTP status code symbols in RSpec?

The response object responds to several of the symbol types as messages. So you can simply do: expect(response).to be_success expect(response).to be_error expect(response).to be_missing expect(response).to be_redirect For the other types, such as :created, you can create a simple custom matcher for this which wraps assert_response: RSpec::Matchers.define :have_status do |type, message = nil| match do |_response| assert_response … Read more