changeset 22:2abc89d58140

more error handling
author casties
date Tue, 01 Oct 2013 18:13:12 +0200
parents 3562adeaba8b
children d24a8673d68e
files zopePubmanConnector.py
diffstat 1 files changed, 12 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/zopePubmanConnector.py	Tue Jul 02 14:47:49 2013 +0200
+++ b/zopePubmanConnector.py	Tue Oct 01 18:13:12 2013 +0200
@@ -74,8 +74,6 @@
         """get all publications der personID"""
         h = httplib2.Http(cacheFolder,timeout=TIMEOUT)
         
-        
-        
         if publicationType is None:
            # cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22&"
             cn = self.connectorString+"cqlQuery=escidoc.publication.creator.person.identifier=%22"+personID+"%22&"
@@ -89,13 +87,16 @@
             cn+="&maximumRecords=%s"%limit
   
         logging.debug(cn)
-        resp, content = h.request(cn)
-    
-       
+        try:
+            resp, content = h.request(cn)
     
-        ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
+            ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
+        
+            root = ET.fromstring(content)
 
-        root = ET.fromstring(content)
+        except Exception, e:
+            logging.error("Error getting and parsing data from PubMan: %s"%e)
+            return []
         
         #<escidocItem:item objid="escidoc:630782" 
         
@@ -112,10 +113,6 @@
             objId = citation.get('objid')
            
             text = citation.find(citationxpath)
-            
-            
-            
-     
   
             idTermPath =""".//escidocMetadataRecords:md-records/escidocMetadataRecords:md-record/escidocMetadataProfile:publication/dc:identifier"""
             #idTermPath =".//{http://purl.org/dc/elements/1.1/}identifier"
@@ -299,15 +296,13 @@
         cn = self.connectorString+"cqlQuery=escidoc.objid=%s&"
         cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
       
-        resp, content = h.request(cn%escidocid)
-        ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
-        logging.debug(cn%escidocid)
-       
         try:
+            resp, content = h.request(cn%escidocid)
+            ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
+            logging.debug(cn%escidocid)
             root = ET.fromstring(content)
         except:
-            logging.error("zopePubmanConnector: cannot parse")
-            logging.error(content)
+            logging.error("zopePubmanConnector: cannot parse: %s"%content)
             return "",''
         
         citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"