Simple use-case: cross domain javascript you will not be able to read the REST header code if you return anything else than 200, you can use special header if you want like X-API-Error: 453 or body error {"error":"123456","errorContext":"Big problem sir!"}
jquery and other libraries wont be able to return you the error, you won't even know there was an error the query will just fail
Cross domain js is emulated using iframes kind of mechanism and if you return 400 your iframe wont load so the jquery callback wont be called and it will just fail silently.
The only reason I recommend for returning non 200 errors is when the request is not properly formated (i.e. not follwoing the protocol/contract like missing parameters and stuff) missing param -> HTTP 400 invalid param value -> HTTP 200 + HTTP Header error code or payload API error code That means that whoever built the client didn't follow the protocol
Simple use-case: cross domain javascript
ReplyDeleteyou will not be able to read the REST header code if you return anything else than 200, you can use special header if you want
like X-API-Error: 453 or body error {"error":"123456","errorContext":"Big problem sir!"}
jquery and other libraries wont be able to return you the error, you won't even know there was an error the query will just fail
Cross domain js is emulated using iframes kind of mechanism and if you return 400 your iframe wont load so the jquery callback wont be called and it will just fail silently.
The only reason I recommend for returning non 200 errors is when the request is not properly formated (i.e. not follwoing the protocol/contract like missing parameters and stuff)
missing param -> HTTP 400
invalid param value -> HTTP 200 + HTTP Header error code or payload API error code
That means that whoever built the client didn't follow the protocol
Yes, that's a good point. Thanks!
ReplyDelete