1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-02-02 01:44:40 +00:00

More properly handle http errors when performing subdomain verify

This commit is contained in:
Hidden Z 2015-10-26 19:59:27 +00:00
parent 6e3862d7ab
commit 9e4cf6273f
2 changed files with 8 additions and 5 deletions

View File

@ -128,14 +128,17 @@ def subdomain(request):
log.debug('trying to open %s', url) log.debug('trying to open %s', url)
resp = opener.open(url, timeout=60) resp = opener.open(url, timeout=60)
except urllib2.URLError, e: except urllib2.URLError, e:
if hasattr(e, 'reason'): error = ''
log.warning('%s: failed to reach server, reason: %s', request.session['topdomain'], e.reason) if hasattr(e, 'code'):
elif hasattr(e, 'code'): error = str(e.code)
log.warning('%s can\'t finish the request, error code: %s', log.warning('%s can\'t finish the request, error code: %s',
request.session['topdomain'], e.code) 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', { return render_to_response('subdomain_http_verify_failure.html', {
'title': settings.SITE_NAME, 'title': settings.SITE_NAME,
'code': e.code, 'error': error,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
else: else:
log.debug('subdomain verification success, saving host') log.debug('subdomain verification success, saving host')

View File

@ -3,7 +3,7 @@
{% block content %} {% block content %}
<p> <p>
{% trans "Verification failed. Webserver returned http code:" %} {{ code }} {% trans "Verification failed. An error occured:" %} {{ error }}
</p> </p>
{% endblock %} {% endblock %}