I\'m using ajax to improve user experience in my Django project. My concern here is how to respond error to browser properly. As far as I know, I can either:
I can't answer whether both methods are acceptable but can only tell you what I do. In my view I catch some specific/explicit errors such as:
I think if you categorize your errors as some specific errors that the user must know about and then everything else then your code will have at the most 2 or 3 return with error routes, which IMHO isn't so bad. I use JSON to return errors and my structure is usually such:
respons={}
response["error|ok"]
response["msg"]="User not found"
response["type"]=ERROR_TYPE # only applicable for errors
Obviously this is quite basic but hopefully gives you a general idea. I would recommend against letting the user see the system generated internal server error. That is horrible user experience, even for internal apps.
Hope this helps.