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

Fix error serializer when using selectable output type #762

Closed
akaihola opened this issue Apr 4, 2019 · 3 comments
Closed

Fix error serializer when using selectable output type #762

akaihola opened this issue Apr 4, 2019 · 3 comments
Labels

Comments

@akaihola
Copy link
Contributor

akaihola commented Apr 4, 2019

After the fix to #753 ("404 not found does not respect default output format"), the error serializer didn't work anymore if using a hug.output_format.accept() construct as the default output format.

An example:

import hug

accept_output = hug.output_format.accept(
        {'application/json': hug.output_format.json,
         'application/pretty-json': hug.output_format.pretty_json},
        default=hug.output_format.json)

hug.defaults.output_format = accept_output

@hug.get('/500')
def error_500():
    raise hug.HTTPInternalServerError('500 Internal Server Error',
                                      'This is an example')
Traceback (most recent call last):
  File "/usr/lib64/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/home/kaiant/.local/lib/python3.7/site-packages/falcon/api.py", line 247, in __call__
    if not self._handle_exception(ex, req, resp, params):
  File "/home/kaiant/.local/lib/python3.7/site-packages/falcon/api.py", line 677, in _handle_exception
    err_handler(ex, req, resp, params)
  File "/home/kaiant/.local/lib/python3.7/site-packages/falcon/api.py", line 655, in _http_error_handler
    self._compose_error_response(req, resp, error)
  File "/home/kaiant/.local/lib/python3.7/site-packages/falcon/api.py", line 649, in _compose_error_response
    self._serialize_error(req, resp, error)
  File "/home/kaiant/repos/python/hug/hug/api.py", line 372, in error_serializer
    response.body = self.output_format({"errors": {error.title: error.description}})
TypeError: output_type() missing 2 required positional arguments: 'request' and 'response'

Looks like the error_serializer() function inside HTTPInterfaceAPI.server() fails to provide the request and response arguments to self.output_format().

@akaihola
Copy link
Contributor Author

akaihola commented Apr 5, 2019

@timothycrosley, did you start working on this? I can create a failing test to start with unless you already did that.

akaihola pushed a commit to akaihola/hug that referenced this issue Apr 5, 2019
HTTP errors now don't crash when formatting the output, even if a
`hug.output_format.accept()` formatter is used.
akaihola pushed a commit to akaihola/hug that referenced this issue Apr 5, 2019
HTTP errors now don't crash when formatting the output, even if a
`hug.output_format.accept()` formatter is used.
akaihola pushed a commit to akaihola/hug that referenced this issue Apr 5, 2019
@timothycrosley
Copy link
Collaborator

I have not started working on this yet, thanks so much for contributing the test case! I'll start working on fixing this tonight - against the giving test case - unless you would like to do so.

Thanks!

~Timothy

@timothycrosley
Copy link
Collaborator

Hi @akaihola,

Your fix has been pushed into PYPI release 2.4.8: https://github.com/timothycrosley/hug/releases/tag/2.4.8

Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants