← Back to team overview

txaws-dev team mailing list archive

[Merge] lp:~clint-fewbar/txaws/fix-keyerror into lp:txaws

 

Clint Byrum has proposed merging lp:~clint-fewbar/txaws/fix-keyerror into lp:txaws.

Requested reviews:
  txAWS Technical List (txaws-tech)
Related bugs:
  Bug #1023627 in txAWS: "Unhandled KeyError when EC2 endpoint's errors are not as expected"
  https://bugs.launchpad.net/txaws/+bug/1023627

For more details, see:
https://code.launchpad.net/~clint-fewbar/txaws/fix-keyerror/+merge/114534

Note that I think this might technically change the API of txaws.. but
it seems to me that it sould be for the better. Still, perhaps its time
txaws went 1.0... *after* this API change. :)
-- 
https://code.launchpad.net/~clint-fewbar/txaws/fix-keyerror/+merge/114534
Your team txAWS Technical List is requested to review the proposed merge of lp:~clint-fewbar/txaws/fix-keyerror into lp:txaws.
=== modified file 'txaws/exception.py'
--- txaws/exception.py	2012-01-26 07:54:16 +0000
+++ txaws/exception.py	2012-07-11 22:40:54 +0000
@@ -110,7 +110,7 @@
         elif count == 0:
             return
         else:
-            return self.errors[0]["Code"]
+            return self.errors[0].get("Code")
 
     def get_error_messages(self):
         count = len(self.errors)
@@ -119,7 +119,7 @@
         elif count == 0:
             return "Empty error list"
         else:
-            return self.errors[0]["Message"]
+            return self.errors[0].get("Message")
 
 
 class AWSResponseParseError(Exception):

=== modified file 'txaws/tests/test_exception.py'
--- txaws/tests/test_exception.py	2010-03-29 17:16:46 +0000
+++ txaws/tests/test_exception.py	2012-07-11 22:40:54 +0000
@@ -112,3 +112,16 @@
         error._set_500_error(XML(xml))
         self.assertEquals(error.errors[0]["Code"], "500")
         self.assertEquals(error.errors[0]["Message"], "Oops")
+        self.assertEquals(error.get_error_codes(), "500")
+
+    def test_no_error_code(self):
+        xml = "<Error><Message>Oops</Message></Error>"
+        error = AWSError("<dummy />", 500)
+        error._set_500_error(XML(xml))
+        self.assertEquals(error.get_error_codes(), None)
+
+    def test_no_error_message(self):
+        xml = "<Error><Code>500</Code></Error>"
+        error = AWSError("<dummy />", 500)
+        error._set_500_error(XML(xml))
+        self.assertEquals(error.get_error_messages(), None)