'Extracts the common "which-format/serialize/return-error-response"
cycle.
Should be used as much as possible to return errors.'

def error_response(self, request, errors, response_class=None):

    if (response_class is None):
        response_class = http.HttpBadRequest
    desired_format = None
    if request:
        if (request.GET.get(u'callback', None) is None):
            try:
                desired_format = self.determine_format(request)
            except BadRequest:
                pass
        else:
            desired_format = u'application/json'
    if (not desired_format):
        desired_format = self._meta.default_format
    try:
        serialized = self.serialize(request, errors, desired_format)
    except BadRequest as e:
        error = u'Additional    errors    occurred,    but    serialization    of    those    errors    failed.'
        if settings.DEBUG:
            error += (u'    %s' % e)
        return response_class(content=error, content_type=u'text/plain')
    return response_class(content=serialized, content_type=build_content_type(desired_format))
