neulhan
neulhan

Reputation: 55

500 error vs 404 error which one is more desirable?

I am a student who is studying the development of django. I have a question about 404 and 500 errors. I handle 404,500 error as 404.html and 500.html respectively.

So, is there a difference between these two error events?

For example,

def example_post_404(request, pk):
    get_object_or_404(Post, id=pk) # code that may occur 404 error

        vs

def example_post_500(request, pk):
    Post.objects.get(id=pk) # code that may occur 500 error

Did 500 error event put more pressure on the server than 404 error event?

Which code is more desirable?

My code is running on AWS EC2 ubuntu-16.04

Upvotes: 1

Views: 1251

Answers (3)

Dash Winterson
Dash Winterson

Reputation: 1295

The difference between any 400 error versus a 500 error is based on whether it is the fault of the client or the server that the request was not parsed.

for instance, a 404 error means the object was not found; what does this mean? it means that based on what the client was asking for, the server could not return a result.

another example, a 503 Service Unavailable; the server recieved the reponse, and although the client request is valid the server was unable to provide the response.

That is the difference between a 4XX error and a 5XX error, if you'd like more detailed information on what to respond with when an error occurs, please refer to the HTTP documentation:

https://www.rfc-editor.org/rfc/rfc2616

Upvotes: 3

Gaurav Goyal
Gaurav Goyal

Reputation: 68

404 Error is Page not found to url calling.

500 is an internal error for our system(like Django un-authenticate user access)

Upvotes: 1

Horatiu Jeflea
Horatiu Jeflea

Reputation: 7414

404 is page not found

500 is an internal system error

If a user requested a page/url that does not exist, return 404. If something happens to your system (like a bug, an unexpected error), return 500.

Upvotes: 2

Related Questions