Created
July 16, 2012 18:04
-
-
Save SeanHayes/3124059 to your computer and use it in GitHub Desktop.
TastyPie: Return 400 Bad Request when deserialization fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie import http | |
from tastypie.exceptions import ImmediateHttpResponse | |
from tastypie.resources import ModelResource | |
class CustomModelResource(ModelResource): | |
def deserialize(self, request, data, format='application/json'): | |
try: | |
return super(CustomModelResource, self).deserialize(request, data, format=format) | |
except Exception as e: | |
# if an exception occurred here it must be due to deserialization | |
raise ImmediateHttpResponse(response=http.HttpBadRequest(e.message)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment