Skip to content

Fix error serializer when using selectable output type #762

@akaihola

Description

@akaihola

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions