You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by GitBox <gi...@apache.org> on 2020/12/07 18:16:49 UTC

[GitHub] [libcloud] dimgal1 commented on a change in pull request #1504: Add support for Linode's API v4

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



##########
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:
       data['errors'] is a list of dictionaries so I think this will not work.
   Maybe it could be something like this?
   ```suggestion
           error_list = []
           for error in data['errors']:
               reason = error.get('reason')
               # The field in the request that caused this error
               field = error.get('field')
               if field is not None:
                   msg = '%s-%s' % (reason, field)
               else:
                   msg = reason
               error_list.append(msg)
           error_msg = ' '.join(error_list)
   ```




----------------------------------------------------------------
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