Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_dev_server swallows falcon.HTTPError and returns 500 #7

Open
lmergner opened this issue Oct 14, 2018 · 0 comments
Open

run_dev_server swallows falcon.HTTPError and returns 500 #7

lmergner opened this issue Oct 14, 2018 · 0 comments

Comments

@lmergner
Copy link

I've been trying out updraft. werkzeug server to swallow falcon's error handling and reraise it as a 500 error.

import falcon
from marshmallow.exceptions import ValidationError
from marshmallow import Schema, fields
from updraft.dev_server import run_dev_server
import logging

logger = logging.getLogger(__name__)


class ErrorSchema(Schema):
    oid = fields.Int(dump_only=True)
    text = fields.Str(required=True)


class Error(object):
    # TODO: Implement

    def on_get(self, req, resp):
        try:
            ErrorSchema().load({"blarg": "Should raise an exception"})
        except ValidationError as e:
            logger.exception(e)
            raise falcon.HTTPBadRequest()


api = falcon.API()
api.add_route("/", Error())
run_dev_server(api, hostname="0.0.0.0", port=5000, use_reloader=True)

Example output

(publicity-zhV7bCdV) lmerg@mergner-darwin in publicity $ http http://localhost:5000/
HTTP/1.0 500 Internal Server Error
Date: Sun, 14 Oct 2018 00:11:48 GMT
Server: BaseHTTP/0.6 Python/3.7.0
content-length: 971
content-type: application/json; charset=UTF-8
vary: Accept

{
    "description": "Traceback (most recent call last):\n  File \"handle.py\", line 23, in on_get\n    ErrorSchema().load({\"blarg\": \"Should raise an exception\"})\n  File \"/Users/lmerg/code/.virtualenvs/publicity-zhV7bCdV/lib/python3.7/site-packages/marshmallow/schema.py\", line 529, in load\n    postprocess=True,\n  File \"/Users/lmerg/code/.virtualenvs/publicity-zhV7bCdV/lib/python3.7/site-packages/marshmallow/schema.py\", line 682, in _do_load\n    raise exc\nmarshmallow.exceptions.ValidationError: {'text': ['Missing data for required field.'], 'blarg': ['Unknown field.']}\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/Users/lmerg/code/contrivers/publicity/falcon/falcon/api.py\", line 247, in __call__\n    responder(req, resp, **params)\n  File \"handle.py\", line 28, in on_get\n    raise falcon.HTTPBadRequest()\nfalcon.errors.HTTPBadRequest\n",
    "title": "500 Internal Server Error"
}

Example expected output (with gunicorn)

(venv) $ http http://localhost:5000/
HTTP/1.1 400 Bad Request
Connection: close
Date: Sun, 14 Oct 2018 00:18:53 GMT
Server: gunicorn/19.9.0
content-length: 28
content-type: application/json; charset=UTF-8
vary: Accept

{
    "title": "400 Bad Request"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant