# Buggy code
def default_serialize_error(req, resp, exception):
    """Serialize the given instance of HTTPError.

    This function determines which of the supported media types, if
    any, are acceptable by the client, and serializes the error
    to the preferred type.

    Currently, JSON and XML are the only supported media types. If the
    client accepts both JSON and XML with equal weight, JSON will be
    chosen.

    Other media types can be supported by using a custom error serializer.

    Note:
        If a custom media type is used and the type includes a
        "+json" or "+xml" suffix, the error will be serialized
        to JSON or XML, respectively. If this behavior is not
        desirable, a custom error serializer may be used to
        override this one.

    Args:
        req: Instance of ``falcon.Request``
        resp: Instance of ``falcon.Response``
        exception: Instance of ``falcon.HTTPError``
    """
    representation = None

    preferred = req.client_prefers(("application/xml", "text/xml", "application/json"))

    if preferred is None:
        # NOTE(kgriffs): See if the client expects a custom media
        # type based on something Falcon supports. Returning something
        # is probably better than nothing, but if that is not
        # desired, this behavior can be customized by adding a
        # custom HTTPError serializer for the custom type.
        accept = req.accept.lower()

        # NOTE(kgriffs): Simple heuristic, but it's fast, and
        # should be sufficiently accurate for our purposes. Does
        # not take into account weights if both types are
        # acceptable (simply chooses JSON). If it turns out we
        # need to be more sophisticated, we can always change it
        # later (YAGNI).
        if "+json" in accept:
            preferred = "application/json"
        elif "+xml" in accept:
            preferred = "application/xml"

    if preferred is not None:
        resp.append_header("Vary", "Accept")
        if preferred == "application/json":
            representation = exception.to_json()
        else:
            representation = exception.to_xml()

        resp.body = representation
        resp.content_type = preferred


# Traceback (AssertionError)
Traceback (most recent call last):
<...snip...>
File "/usr/local/lib/python2.7/dist-packages/falcon/api.py", line 247, in __call__
start_response(resp.status, headers)
File "/usr/lib/python2.7/wsgiref/validate.py", line 167, in start_response_wrapper
check_content_type(status, headers)
File "/usr/lib/python2.7/wsgiref/validate.py", line 419, in check_content_type
assert_(0, "No Content-Type header found in headers (%s)" % headers)
File "/usr/lib/python2.7/wsgiref/validate.py", line 129, in assert_
raise AssertionError(*args)
AssertionError: No Content-Type header found in headers ([('content-length', '0')])

# Fixed code
def default_serialize_error(req, resp, exception):
    """Serialize the given instance of HTTPError.

    This function determines which of the supported media types, if
    any, are acceptable by the client, and serializes the error
    to the preferred type.

    Currently, JSON and XML are the only supported media types. If the
    client accepts both JSON and XML with equal weight, JSON will be
    chosen.

    Other media types can be supported by using a custom error serializer.

    Note:
        If a custom media type is used and the type includes a
        "+json" or "+xml" suffix, the error will be serialized
        to JSON or XML, respectively. If this behavior is not
        desirable, a custom error serializer may be used to
        override this one.

    Args:
        req: Instance of ``falcon.Request``
        resp: Instance of ``falcon.Response``
        exception: Instance of ``falcon.HTTPError``
    """
    representation = None

    preferred = req.client_prefers(("application/xml", "text/xml", "application/json"))

    if preferred is None:
        # NOTE(kgriffs): See if the client expects a custom media
        # type based on something Falcon supports. Returning something
        # is probably better than nothing, but if that is not
        # desired, this behavior can be customized by adding a
        # custom HTTPError serializer for the custom type.
        accept = req.accept.lower()

        # NOTE(kgriffs): Simple heuristic, but it's fast, and
        # should be sufficiently accurate for our purposes. Does
        # not take into account weights if both types are
        # acceptable (simply chooses JSON). If it turns out we
        # need to be more sophisticated, we can always change it
        # later (YAGNI).
        if "+json" in accept:
            preferred = "application/json"
        elif "+xml" in accept:
            preferred = "application/xml"

    if preferred is not None:
        resp.append_header("Vary", "Accept")
        if preferred == "application/json":
            representation = exception.to_json()
        else:
            representation = exception.to_xml()

        resp.body = representation
        resp.content_type = preferred + "; charset=UTF-8"