From: Michael Tremer Date: Sun, 7 Sep 2014 18:42:12 +0000 (+0000) Subject: Handle HTTP error 404 generically X-Git-Tag: 005~16 X-Git-Url: http://git.ipfire.org/?p=oddments%2Fddns.git;a=commitdiff_plain;h=ff43fa7041a5f948aa7f92047fbc53ea5b1a461f Handle HTTP error 404 generically --- diff --git a/src/ddns/errors.py b/src/ddns/errors.py index 58928f3..293b4eb 100644 --- a/src/ddns/errors.py +++ b/src/ddns/errors.py @@ -109,6 +109,13 @@ class DDNSNetworkUnreachableError(DDNSNetworkError): reason = N_("Network unreachable") +class DDNSNotFound(DDNSError): + """ + Thrown when the called URL has not been found + """ + reason = N_("Not found") + + class DDNSRequestError(DDNSError): """ Thrown when a request could diff --git a/src/ddns/providers.py b/src/ddns/providers.py index a5385a9..271f2c3 100644 --- a/src/ddns/providers.py +++ b/src/ddns/providers.py @@ -1186,11 +1186,8 @@ class DDNSProviderZZZZ(DDNSProvider): response = self.send_request(url, data=data) # Handle error codes. - except urllib2.HTTPError, e: - if e.code == 404: - raise DDNSRequestError(_("Invalid hostname specified.")) - - raise + except DDNSNotFound: + raise DDNSRequestError(_("Invalid hostname specified")) # Handle success messages. if response.code == 200: diff --git a/src/ddns/system.py b/src/ddns/system.py index 79bf192..8415579 100644 --- a/src/ddns/system.py +++ b/src/ddns/system.py @@ -180,6 +180,12 @@ class DDNSSystem(object): elif e.code in (401, 403): raise DDNSAuthenticationError(e.reason) + # 404 - Not found + # Either the provider has changed the API, or + # there is an error on the server + elif e.code == 404: + raise DDNSNotFound(e.reason) + # 500 - Internal Server Error elif e.code == 500: raise DDNSInternalServerError(e.reason)