libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [libcloud] micafer commented on a change in pull request #1504: Add support for Linode's API v4
Date Mon, 07 Dec 2020 09:07:28 GMT

micafer commented on a change in pull request #1504:
URL: https://github.com/apache/libcloud/pull/1504#discussion_r537339237



##########
File path: libcloud/common/linode.py
##########
@@ -163,3 +176,119 @@ def add_default_params(self, params):
         # Be explicit about this in case the default changes.
         params["api_responseFormat"] = "json"
         return params
+
+
+class LinodeExceptionV4(Exception):
+    def __init__(self, message):
+        self.message = message
+
+    def __str__(self):
+        return "%s" % self.message
+
+    def __repr__(self):
+        return "<LinodeException '%s'>" % self.message
+
+
+class LinodeResponseV4(JsonResponse):
+    valid_response_codes = [httplib.OK, httplib.NO_CONTENT, ]
+
+    def parse_body(self):
+        """Parse the body of the response into JSON objects
+        :return: ``dict`` of objects"""
+        return super(LinodeResponseV4, self).parse_body()
+
+    def parse_error(self):
+        """
+        Parse the error body and raise the appropriate exception
+        """
+        status = int(self.status)
+        data = self.parse_body()
+        # Use only the first error, as there'll be only one most of the time
+        error = data['errors'][0]

Review comment:
       Why not:
   error = " ".join(data['errors'])
   In this case all error messages will be returned, not only the first one.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message