toastdriven/django-tastypie — pull request #284 by lionelbarrow (2011-11-09 20:54:50+00:00)
Title: A specific error message for JSON decoding problems

My company uses Tastypie to power our restful, JSON-based API. For the most part, it works great! We do have one issue, however.

A few users of our API have complained that we do not return descriptive error messages when we receive malformed JSON in a post request -- this makes it hard for people writing applications using our API to debug. Because Tastypie decodes JSON before the API request is sent to Django, there isn't really a way for us customize our error message without modifying Tastypie.

The commit in this pull request adds a specific error message for JSON decoding problems. The only change is the addition of a few lines to resources/Resource._handle_500 that check if an incoming exception is of the type thrown by the JSON decoder when it fails. If so, the error message directs to user to check their JSON syntax.