wlanslovenija / django-tastypie-mongoengine

MongoEngine support for django-tastypie.
Other
73 stars 59 forks source link

Raise BadRequest rather than AssertionError in MongoEngineResource.dispatch() #66

Open dcooper opened 10 years ago

dcooper commented 10 years ago

If an API client sends an invalid request to the API server, the server should return a 4xx response rather than a 5xx response.

The dispatch() method on MongoEngineResource raises AssertionError when testing the request method. If dispatch() was to raise tastypie_exceptions.BadRequest rather than AssertionError, then tastypie will return an HTTP 400 to the client rather than an HTTP 500.

In the 0.4.2 version of tastypie_mongoengine, the AssertionError exceptions are raised in the following places: tastypie_mongoengine/resources.py:373 tastypie_mongoengine/resources.py:376

mitar commented 10 years ago

Are you sure this should not be checked already in Tastypie? Here is assert just to assure we are using Tastypie API properly.

But if you want, you can make a pull request with this change and please add tests which send invalid requests and fail.