human
Complete the below
def handle_es_errors(template, status_code=503):

    ''''Handles Elasticsearch exceptions for views
    Wrap the entire view in this and don\'t worry about Elasticsearch exceptions
    again!
    :arg template: template path string or function to generate the template
    path string for HTML requests
    :arg status_code: status code to return
    :returns: content-type-appropriate HttpResponse'
    '''

=====
What is a the Python code you requested?
assistant
#Here is the Python code you requested.
    def handler(fun):
        @wraps(fun)
        def _handler(request, *args, **kwargs):
            try:
                return fun(request, *args, **kwargs)
            except ES_EXCEPTIONS as exc:
                is_json = (request.GET.get('format') == 'json')
                callback = request.GET.get('callback', '').strip()
                content_type = ('application/x-javascript' if callback else 'application/json')
                if is_json:
                    return HttpResponse(json.dumps({'error': _('Search    Unavailable')}), content_type=content_type, status=status_code)
                if callable(template):
                    actual_template = template(request, *args, **kwargs)
                else:
                    actual_template = template
                log.exception(exc)
                return render(request, actual_template, status=503)
        return _handler
    return handler