From 9e4cf6273fab5088b0ef29c07d0079f265c9a471 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Mon, 26 Oct 2015 19:59:27 +0000 Subject: [PATCH] More properly handle http errors when performing subdomain verify --- pyi2phosts/postkey/views.py | 11 +++++++---- .../templates/subdomain_http_verify_failure.html | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyi2phosts/postkey/views.py b/pyi2phosts/postkey/views.py index cbae2bc..048a052 100644 --- a/pyi2phosts/postkey/views.py +++ b/pyi2phosts/postkey/views.py @@ -128,14 +128,17 @@ def subdomain(request): log.debug('trying to open %s', url) resp = opener.open(url, timeout=60) except urllib2.URLError, e: - if hasattr(e, 'reason'): - log.warning('%s: failed to reach server, reason: %s', request.session['topdomain'], e.reason) - elif hasattr(e, 'code'): + error = '' + if hasattr(e, 'code'): + error = str(e.code) log.warning('%s can\'t finish the request, error code: %s', request.session['topdomain'], e.code) + if hasattr(e, 'reason'): + error += ' - ' + str(e.reason) + log.warning('%s: failed to reach server, reason: %s', request.session['topdomain'], e.reason) return render_to_response('subdomain_http_verify_failure.html', { 'title': settings.SITE_NAME, - 'code': e.code, + 'error': error, }, context_instance=RequestContext(request)) else: log.debug('subdomain verification success, saving host') diff --git a/pyi2phosts/templates/subdomain_http_verify_failure.html b/pyi2phosts/templates/subdomain_http_verify_failure.html index 4869a82..5fcd99a 100644 --- a/pyi2phosts/templates/subdomain_http_verify_failure.html +++ b/pyi2phosts/templates/subdomain_http_verify_failure.html @@ -3,7 +3,7 @@ {% block content %}

-{% trans "Verification failed. Webserver returned http code:" %} {{ code }} +{% trans "Verification failed. An error occured:" %} {{ error }}

{% endblock %}