Commits

Pablo Abdelhay  committed 5f7b769

Created JsonErrorResponse in http.responses.
Same as JsonResponse, but sending an HttpResponseBadResquest instead.

  • Participants
  • Parent commits 5e3d3e7

Comments (0)

Files changed (1)

File inoa/http/responses.py

     """
     cls = cls or ExtendedJSONEncoder
     return HttpResponse(simplejson.dumps(data, cls=cls), mimetype="application/json")
+
+def JsonErrorResponse(data, cls=None):
+    """
+    Returns an HttpResponseBadRequest with JSON content type. Converts the data parameter to JSON automatically.
+    Errors can be accessed parsing the 'responseText' attribute of the Http response.
+    """
+    cls = cls or ExtendedJSONEncoder
+    return HttpResponseBadRequest(simplejson.dumps(data, cls=cls), mimetype="application/json")
+