toastdriven/django-tastypie — Issue #285: Specific error message for JSON decoding errors
Author: lionelbarrow
Created: 2011-11-09 20:56:21+00:00
State: open

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.

I've sent a pull request that 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.

You can see the pull request here: https://github.com/toastdriven/django-tastypie/pull/284