]> git.ipfire.org Git - oddments/ddns.git/commitdiff
Handle HTTP errors as early as possible.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 22 Jun 2014 12:23:07 +0000 (12:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 22 Jun 2014 12:23:07 +0000 (12:23 +0000)
src/ddns/providers.py
src/ddns/system.py

index ece4b37b888211a05d0a39088d1883012bf0109e..a729a2263c78197525679aaf4714f13f460b155a 100644 (file)
@@ -190,19 +190,9 @@ class DDNSProviderAllInkl(DDNSProvider):
        url = "http://dyndns.kasserver.com"
 
        def update(self):
-
                # There is no additional data required so we directly can
                # send our request.
-               try:
-                       # Send request to the server.
-                       response = self.send_request(self.url, username=self.username, password=self.password)
-
-                       # Handle 401 HTTP Header (Authentication Error)
-               except urllib2.HTTPError, e:
-                       if e.code == 401:
-                               raise DDNSAuthenticationError
-
-                       raise
+               response = self.send_request(self.url, username=self.username, password=self.password)
 
                # Get the full response message.
                output = response.read()
@@ -244,10 +234,6 @@ class DDNSProviderDHS(DDNSProvider):
                if response.code == 200:
                        return
 
-               # Handle error codes.
-               elif response.code == 401:
-                       raise DDNSAuthenticationError
-
                # If we got here, some other update error happened.
                raise DDNSUpdateError
 
@@ -542,12 +528,6 @@ class DDNSProviderLightningWireLabs(DDNSProvider):
                if response.code == 200:
                        return
 
-               # Handle error codes.
-               if response.code == 403:
-                       raise DDNSAuthenticationError
-               elif response.code == 400:
-                       raise DDNSRequestError
-
                # If we got here, some other update error happened.
                raise DDNSUpdateError
 
index afc5a5fbc0217deb62fb44cf42e78f2e1aeb4dcd..ef525fb942742f9670c174180c167c1be189e4cc 100644 (file)
@@ -168,9 +168,22 @@ class DDNSSystem(object):
                        return resp
 
                except urllib2.HTTPError, e:
+                       # 400 - Bad request
+                       if e.code == 400:
+                               raise DDNSRequestError(e.reason)
+
+                       # 401 - Authorization Required
+                       # 403 - Forbidden
+                       elif e.code in (401, 403):
+                               raise DDNSAuthenticationError(e.reason)
+
+                       # 500 - Internal Server Error
+                       elif e.code == 500:
+                               raise DDNSInternalServerError(e.reason)
+
                        # 503 - Service Unavailable
-                       if e.code == 503:
-                               raise DDNSServiceUnavailableError
+                       elif e.code == 503:
+                               raise DDNSServiceUnavailableError(e.reason)
 
                        # Raise all other unhandled exceptions.
                        raise