Skip to content

Commit

Permalink
fixes bug 1052007 - Switch to ujson for parsing middleware JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Aug 11, 2014
1 parent 5344d3e commit 0a9058c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion webapp-django/crashstats/api/views.py
Expand Up @@ -267,7 +267,12 @@ def model_wrapper(request, model_name):
)
raise
except ValueError as e:
if 'No JSON object could be decoded' in e:
if (
# built in json module ValueError
'No JSON object could be decoded' in e or
# ujson module ValueError
'Expected object or value' in e
):
return http.HttpResponse(
'Not a valid JSON response',
status=400
Expand Down
4 changes: 3 additions & 1 deletion webapp-django/crashstats/crashstats/models.py
Expand Up @@ -13,6 +13,8 @@
import stat
import time

import ujson

from django.conf import settings
from django.core.cache import cache
from django.utils.encoding import iri_to_uri
Expand Down Expand Up @@ -264,7 +266,7 @@ def fetch(

result = resp.content
if expect_json:
result = json.loads(result)
result = ujson.loads(result)

if cache_key:
cache.set(cache_key, result, self.cache_seconds)
Expand Down

0 comments on commit 0a9058c

Please sign in to comment.