Tobia
Tobia

Reputation: 9506

Ajax call best practice: logical error through HTTP error

Is there any reason to avoid to send logical error as an HTTP 500 error? I'm developing a web-app, after an Ajax call I have the default error handler that shows a modal notice with the text of the error.

In some case the error can be logical ('ID not found' or 'The input is not a number' ...), in these cases can I send a HTTP error or it should be reserved only for trasportation/authentication error?

Upvotes: 0

Views: 126

Answers (1)

arkascha
arkascha

Reputation: 42915

This certainly is possible from a technical point of view, but I would advise against it. Reason is that you confuse a logical error in the request and a processing error in the processing. Those should be kept separate.

Instead I suggest you use http code 406 Not Acceptable. It signals that the request has been received, but will not be processed because "it does not make sense". I'd say that is more suitable.

Upvotes: 1

Related Questions