Skip to content
  • Denis Laxalde's avatar
    Detect bad mime types upon data submission views · d2b673a15823
    Denis Laxalde authored
    Previously, we did "request.json_body" in every data submission views
    (like entity creation or update, with HTTP method being POST or PUT).
    This instruction might fail with JSONDecodeError exception if the body
    fails to JSON decode. This would result in a 500 error response. Rather
    we want to return a 40x response indicating that this is a client error.
    
    So we now raise a 415 Unsupported Media Type error through a
    _json_body() helper function every times we need to decode JSON body of
    incoming requests. Notice that since json module only has
    JSONDecodeError exception on Python3+, we catch ValueError on Python2.
    
    A functional test is added for entity creation view.
    d2b673a15823