소스 검색

More robust error handling

Andrej 4 년 전
부모
커밋
982c914fbb
1개의 변경된 파일13개의 추가작업 그리고 3개의 파일을 삭제
  1. 13 3
      labkeyBrowser/slicerNetwork.py

+ 13 - 3
labkeyBrowser/slicerNetwork.py

@@ -17,6 +17,10 @@ class slicerNetwork(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
         self.parent.title="slicerNetwork"
         self.parent.title="slicerNetwork"
         pass
         pass
 
 
+
+class DummyResponse:
+    pass
+
 class labkeyURIHandler(slicer.vtkURIHandler):
 class labkeyURIHandler(slicer.vtkURIHandler):
     def __init__(self):
     def __init__(self):
         slicer.vtkURIHandler.__init__(self)
         slicer.vtkURIHandler.__init__(self)
@@ -225,7 +229,7 @@ class labkeyURIHandler(slicer.vtkURIHandler):
         debug=True
         debug=True
         if debug:
         if debug:
             print("GET: {0}".format(url))
             print("GET: {0}".format(url))
-            print("as {0}".format(self.auth_name))
+            print("as {0}".format(self.connectionConfig['labkey']['user']))
         headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
         headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
         try:
         try:
             if not binary:
             if not binary:
@@ -235,8 +239,11 @@ class labkeyURIHandler(slicer.vtkURIHandler):
         #f contains json as a return value
         #f contains json as a return value
         #f contains json as a return value
         #f contains json as a return value
         except urllib3.exceptions.HTTPError as e:
         except urllib3.exceptions.HTTPError as e:
-            print(e)
-            return e
+            print("HTTP error {}".format(e))
+            response=DummyResponse()
+            response.status=1000
+            response.data=str(e)
+            return response
 
 
     #a HEAD request
     #a HEAD request
     def head(self,url):
     def head(self,url):
@@ -346,9 +353,12 @@ class labkeyURIHandler(slicer.vtkURIHandler):
         url=self.GetLabkeyUrl()+'/login/whoAmI.view'
         url=self.GetLabkeyUrl()+'/login/whoAmI.view'
         try:
         try:
             response=self.get(url)
             response=self.get(url)
+            if not labkeyURIHandler.HTTPStatus(response):
+                return None
             encoding=chardet.detect(response.data)['encoding']
             encoding=chardet.detect(response.data)['encoding']
             jsonData=json.loads(response.data.decode(encoding))
             jsonData=json.loads(response.data.decode(encoding))
         except AttributeError:
         except AttributeError:
+            print("Response: {}".response.data)
             print("Failed")
             print("Failed")
             return None
             return None
         #local cookie jar
         #local cookie jar