Difference between 404 and 410 error code
Asked Answered
A

1

13

I have read about many error code but I am little-bit confuse about Error code 404 and 410. I didn’t distinguish till now what these errors exactly pretend.

Airframe answered 5/3, 2015 at 11:26 Comment(0)
J
15

The 404 indicates, that the resource is not present at the given location, and it has probably never been (or server has no idea whether it has been).

The 410, on the other hand, indicates that resource is not present anymore, but it used to be there in the past. It's a useful hint for some clients such as search engines, spiders etc., because they can remove this resource from their indexes.

From the HTTP 1.1 original RFC 2616 section 10.4.11:

The 410 response is primarily intended to assist the task of web maintenance by notifying the recipient that the resource is intentionally unavailable and that the server owners desire that remote links to that resource be removed. Such an event is common for limited-time, promotional services and for resources belonging to individuals no longer working at the server's site. It is not necessary to mark all permanently unavailable resources as "gone" or to keep the mark for any length of time -- that is left to the discretion of the server owner.

Also, about the difference between the two:

This condition [the 410] is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead.

It has been later rephrased in RFC 7231 section 6.5.4, but the meaning remains the same:

A 404 status code does not indicate whether this lack of representation is temporary or permanent; the 410 (Gone) status code is preferred over 404 if the origin server knows, presumably through some configurable means, that the condition is likely to be permanent.

Johnston answered 5/3, 2015 at 11:29 Comment(8)
It deeply, deeply annoys me that virtually every rotten link points to a 404, not to a 410. Lazy backend devs.Ostium
@Ostium Seems to be right to me though. New links might match some old links by coincidence, so generally speaking it's more right to use 404Cookie
@JimmyT. except if you know for a fact that no resource will ever be available on that link, which is the case with expired resources, that are still available in the database but the client is not supposed to access it anymore.Lewandowski
@Lewandowski if the underlying software changes or the database gets reorganized you can't be sure about thatCookie
Not necessarily lazy backend devs, @DavidsKanal. Speaking as a .net dev, I would have to go out of my way in the code we usually write for accessing rows to generate a distinction between 404 and 410. Consider soft deletes. You know the row is permanently gone, but the defacto query engine (EF) will not easily let you distinguish between a row which doesn't exist vs one which has merely been soft deleted without having to write the entire query yourself. Even that will be inefficient in terms of performance.Imogen
Yeah I see that now. Dunno why my comment from 3 years ago sounds so needlessly pissy. I mean it still annoys me but blaming devs for being lazy was not the right responseOstium
Make the difference in single query is pretty easy: - The entity physically exist: 200, - The entity physically does not exist : 404 - The entity logically does not exist, and might be a comeback: 404 - The entity logically does not exist, and there is no comeback: 410Heteronomy
With a "select e.Id, e.Name, e.IsSoftDeleted from Entity e where e.Id = 1" we can do that 4 outcomes; if returns a entity, that is not soft deleted, then 200; if returns a entity that is soft deleted, based on the business rules is a 404 or a 410; if returns no entity, then is 404Heteronomy

© 2022 - 2024 — McMap. All rights reserved.