]> git.ipfire.org Git - oddments/ddns.git/commitdiff
Handle HTTP error 404 generically
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Sep 2014 18:42:12 +0000 (18:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Sep 2014 18:42:12 +0000 (18:42 +0000)
src/ddns/errors.py
src/ddns/providers.py
src/ddns/system.py

index 58928f30c4da73cf01aa39c09f7fff8405b3ab05..293b4eb8f58510c8e1c8d6218220e80584c8eb10 100644 (file)
@@ -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
index a5385a9c6b1bb25c12d11dd5950d0aac74bff917..271f2c3658f88ba18148a0ded188878902f8b2c4 100644 (file)
@@ -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:
index 79bf19212c04ea08a1fdb80117bbceb5ceee1365..8415579455763369a0a9ac844841ab2ee1f39945 100644 (file)
@@ -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)