Add exception for HTTP 429 status codes.
authorDirk Wagner <dirk.wagner@ipfire.org>
Fri, 24 Feb 2017 10:26:06 +0000 (11:26 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 24 Feb 2017 10:26:06 +0000 (11:26 +0100)
This commit adds support for handling HTTP 429 status codes and a new
exeption class for calling "To many requests" exceptions.

This class easily can be used to catch similar responses from other
DDNS providers too.

Signed-off-by: Dirk Wagner <dirk.wagner@ipfire.org>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
src/ddns/errors.py
src/ddns/system.py

index 58a5ba9..a8a2017 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # ddns - A dynamic DNS client for IPFire                                      #
-# Copyright (C) 2012 IPFire development team                                  #
+# Copyright (C) 2012-2017 IPFire development team                             #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
@@ -161,6 +161,13 @@ class DDNSServiceUnavailableError(DDNSNetworkError):
        reason = N_("Service unavailable")
 
 
+class DDNSTooManyRequests(DDNSError):
+       """
+               Raised when too many requests occured.
+       """
+       reason = N_("Too many requests")
+
+
 class DDNSUpdateError(DDNSError):
        """
                Thrown when an update could not be
index c268ba5..67ea553 100644 (file)
@@ -194,6 +194,10 @@ class DDNSSystem(object):
                        elif e.code == 404:
                                raise DDNSNotFound(e.reason)
 
+                       # 429 - Too Many Requests
+                       elif e.code == 429:
+                               raise DDNSTooManyRequests(e.reason)
+
                        # 500 - Internal Server Error
                        elif e.code == 500:
                                raise DDNSInternalServerError(e.reason)