'Override the default serializer for instances of :class:`~.HTTPError`.
When a responder raises an instance of :class:`~.HTTPError`,
Falcon converts it to an HTTP response automatically. The
default serializer supports JSON and XML, but may be overridden
by this method to use a custom serializer in order to support
other media types.
Note:
If a custom media type is used and the type includes a
"+json" or "+xml" suffix, the default serializer will
convert the error to JSON or XML, respectively.
The :class:`~.HTTPError` class contains helper methods,
such as `to_json()` and `to_dict()`, that can be used from
within custom serializers. For example::
def my_serializer(req, resp, exception):
representation = None
preferred = req.client_prefers((\'application/x-yaml\',
\'application/json\'))
if preferred is not None:
if preferred == \'application/json\':
representation = exception.to_json()
else:
representation = yaml.dump(exception.to_dict(),
encoding=None)
resp.body = representation
resp.content_type = preferred
resp.append_header(\'Vary\', \'Accept\')
Args:
serializer (callable): A function taking the form
``func(req, resp, exception)``, where `req` is the request
object that was passed to the responder method, `resp` is
the response object, and `exception` is an instance of
``falcon.HTTPError``.'

def set_error_serializer(self, serializer):

    if (len(get_argnames(serializer)) == 2):
        serializer = helpers.wrap_old_error_serializer(serializer)
    self._serialize_error = serializer
