[ckan-changes] commit/ckanclient: dread: Added more detailed exceptions.

Bitbucket commits-noreply at bitbucket.org
Thu Jul 14 11:16:15 UTC 2011


1 new changeset in ckanclient:

http://bitbucket.org/okfn/ckanclient/changeset/b9d296107f88/
changeset:   b9d296107f88
user:        dread
date:        2011-07-14 13:15:23
summary:     Added more detailed exceptions.
affected #:  1 file (546 bytes)

--- a/ckanclient/__init__.py	Thu Jun 23 15:30:32 2011 +0100
+++ b/ckanclient/__init__.py	Thu Jul 14 12:15:23 2011 +0100
@@ -1,4 +1,4 @@
-__version__ = '0.7'
+__version__ = '0.8'
 __description__ = 'The CKAN client Python package.'
 __long_description__ = \
 '''The CKAN client software may be used to make requests on the Comprehensive
@@ -72,7 +72,13 @@
 Changelog
 =========
 
-v0.7 2010-01-27
+v0.8 2011-XX-XX
+---------------
+
+  * More detailed exceptions added
+
+
+v0.7 2011-01-27
 ---------------
 
   * Package search returns results as a generator
@@ -131,8 +137,10 @@
 logger = logging.getLogger('ckanclient')
 
 
-class CkanApiError(Exception):
-    pass
+class CkanApiError(Exception): pass
+class CkanApiNotFoundError(CkanApiError): pass
+class CkanApiNotAuthorizedError(CkanApiError): pass
+class CkanApiConflictError(CkanApiError): pass
 
 class Request(urllib2.Request):
     def __init__(self, url, data=None, headers={}, method=None):
@@ -303,7 +311,14 @@
     def open_url(self, url, *args, **kwargs):
         result = super(CkanClient, self).open_url(url, *args, **kwargs)
         if self.last_status not in (200, 201):
-            raise CkanApiError(self.last_message)
+            if self.last_status == 404:
+                raise CkanApiNotFoundError(self.last_status)
+            elif self.last_status == 403:
+                raise CkanApiNotAuthorizedError(self.last_status)
+            elif self.last_status == 409:
+                raise CkanApiConflictError(self.last_status)
+            else:
+                raise CkanApiError(self.last_message)
         return result
             
     def api_version_get(self):

Repository URL: https://bitbucket.org/okfn/ckanclient/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list