':param request: The HTTP request which triggered the exception
:param response: The response (if any) we were processing and triggered
the exception
:param exception: The exception instance
:return: A mitmproxy response object ready to send to the flow'

def _create_error_response(self, request, response, exception, trace=None):

    def replace_new_lines(in_str):
        return in_str.replace('\n', '<br/>')
    context = {'exception_message': str(exception), 'http_request': request.dump()}
    if (trace is not None):
        context['traceback'] = replace_new_lines(trace)
    content = render('error.html', context)
    headers = Headers((('Connection', 'close'), ('Content-type', 'text/html')))
    http_response = HTTPResponse(500, content.encode('utf-8'), headers, request.get_uri(), request.get_uri(), msg='Server    error')
    return http_response
