Bug 1127821

Summary: Malformed JSON results in a 500 response
Product: [Retired] Pulp Reporter: Jeremy Cline <jcline>
Component: API/integrationAssignee: amacdona <austin>
Status: CLOSED UPSTREAM QA Contact: pulp-qe-list
Severity: low Docs Contact:
Priority: medium    
Version: MasterCC: austin, skarmark
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-02-28 22:14:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Jeremy Cline 2014-08-07 15:38:16 UTC
Description of problem:
If you pass unparsable JSON to Pulp, it results in a 500. 

Version-Release number of selected component (if applicable): master


How reproducible:


Steps to Reproduce:
1. curl -i -H "Accept: application/json" -X POST -d '{"oh_no": "I_forgot_a_closing_mustachio"' -u admin:admin -k 'https://localhost/pulp/api/v2/repositories/'
2.
3.

Actual results:
HTTP/1.1 500 Internal Server Error
Date: Thu, 07 Aug 2014 15:35:05 GMT
Server: Apache/2.4.10 (Fedora) OpenSSL/1.0.1e-fips mod_wsgi/3.5 Python/2.7.5
Content-Encoding: utf-8
Content-Length: 4686
Connection: close
Content-Type: application/json

{
    "_href": "/pulp/api/v2/repositories/",
    "error_message": "Unhandled Exception",
    "exception": [
        "ValueError: Expecting object: line 1 column 40 (char 39)\n"
    ],
    "http_request_method": "POST",
    "http_status": 500,
    "traceback": [
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/middleware/exception.py\", line 44, in __call__\n    return self.app(environ, start_response)\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/middleware/postponed.py\", line 42, in __call__\n    return self.app(environ, start_response)\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 279, in wsgi\n    result = self.handle_with_processors()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 29, in _handle_with_processors\n    return process(self.processors)\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in process\n    return p(lambda: process(processors))\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 566, in processor\n    return handler()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in <lambda>\n    return p(lambda: process(processors))\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in process\n    return p(lambda: process(processors))\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 581, in processor\n    result = handler()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in <lambda>\n    return p(lambda: process(processors))\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 28, in process\n    return self.handle()\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 230, in handle\n    return self._delegate(fn, self.fvars, args)\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 422, in _delegate\n    return f()\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 430, in <lambda>\n    f = lambda: self._delegate_sub_application(pat, what)\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 455, in _delegate_sub_application\n    return app.handle_with_processors()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 29, in _handle_with_processors\n    return process(self.processors)\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in process\n    return p(lambda: process(processors))\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 566, in processor\n    return handler()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in <lambda>\n    return p(lambda: process(processors))\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in process\n    return p(lambda: process(processors))\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 581, in processor\n    result = handler()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 26, in <lambda>\n    return p(lambda: process(processors))\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/application.py\", line 28, in process\n    return self.handle()\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 230, in handle\n    return self._delegate(fn, self.fvars, args)\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 420, in _delegate\n    return handle_class(cls)\n",
        "  File \"/usr/lib/python2.7/site-packages/web/application.py\", line 396, in handle_class\n    return tocall(*args)\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/controllers/decorators.py\", line 227, in _auth_decorator\n    value = method(self, *args, **kwargs)\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/controllers/repositories.py\", line 149, in POST\n    repo_data = self.params()\n",
        "  File \"/home/jcline/devel/pulp/server/pulp/server/webservices/controllers/base.py\", line 67, in params\n    deserialized_data = json.loads(data)\n",
        "  File \"/usr/lib64/python2.7/json/__init__.py\", line 338, in loads\n    return _default_decoder.decode(s)\n",
        "  File \"/usr/lib64/python2.7/json/decoder.py\", line 365, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n",
        "  File \"/usr/lib64/python2.7/json/decoder.py\", line 381, in raw_decode\n    obj, end = self.scan_once(s, idx)\n"
    ]
}


Expected results:
Something a little more graceful

Additional info:

Comment 1 Brian Bouterse 2015-02-28 22:14:35 UTC
Moved to https://pulp.plan.io/issues/482