Does serving a 404 page still allow the response of 404 as the response code? or is it technically a 200 since it is serving the custom 404 page successfully?
Does serving a 404 page still allow the response of 404 as the response code? or is it technically a 200 since it is serving the custom 404 page successfully?
The browser usually has no special handling for most response codes, so serving a 404 page with a 404 status code is fine/expected and lets things (browser, scraper, etc) respond appropriately. I don't think the browser treats it specially but if you were scraping, you'd obviously want to ignore that result.
It is frustrating to work with APIs that return something like 200 { meta: { status: 404 message: "field <x> not found" } }
and browsing is no different.
If you happened to know that the page was www.ycombinator.com/error404.html Then you could load that page directly and it would return 200 OK
Technically you could have a website where you serve real web pages full of content using the (wrong) 404 code, or serve web pages that tell the user "not found" using the (wrong) 200 code. It would massively mess up bots, search engines, browser extensions, and any other software that needs to know whether a page actually exists - but it would be fully browsable like normal by a human with a web browser, since humans don't see or read HTTP headers.
Basically: 404 tells crawlers that the URL is invalid.
The HTTP server also has to return something,. It could simply return 0-length content and allow the browser to show its error page, but that wouldn't be "on brand."
So, 404 would be used in case the database endpoint does not exist at the URL you tried to access it at. A query returning zero rows would be a "success" in HTTP terms.
An example of where the browser might ignore the body is in a 301 redirect.
By convention, if you don't return enough content, the browser will render it's own not found, but if you do it'll render it.
Btw there is a status code 204 which means ok but no response body.