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 58928f3..293b4eb 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 a5385a9..271f2c3 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 79bf192..8415579 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)