Commit 3c48de5d authored by Franziska Koehn's avatar Franziska Koehn
Browse files

new Exception classes implemented

parent 6a92b1d4
class Error(Exception):
pass
class ServerNotFoundError(Error):
pass
class DatabaseError(Error):
pass
class UnauthorizedError(Error):
pass
class ResponseNotReady(Error):
pass
class EmptyResultset(Error):
pass
class QueryError(Error):
pass
......@@ -33,32 +33,29 @@ class XnatSearchApp(gtk.Window):
fields = type_reader.get_fields_from_labels(labels,root_type)
import xsalogic.queries as queries
query_results = queries.search_for( host,
root_type,
query,
fields,
user,
passw
)
#TODO catch errors
#httplib.ResponseNotReady
#one message dialog for all
if query_results is "DatabaseError":
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="Error! Check your query."
)
import xsa.errors as xsa_errors
try:
query_results = queries.search_for( host,
root_type,
query,
fields,
user,
passw
)
except xsa_errors.Error as e:
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format=str(e)
)
md.run()
md.destroy()
self.results = []
elif query_results is "ServerNotFoundError":
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="Error! Server not found."
)
except Exception:
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="An unexpected Error was raised."
)
md.run()
md.destroy()
self.results = []
......
......@@ -73,31 +73,42 @@ def download_file(host, project, subject, experiment, scan, file_name):
def search_for(host, root_element, constraints, search_fields, user, passw):
from pyxnat import Interface
import xsa.errors as xsa_errors
from pyxnat.core import errors
from tempfile import mkdtemp
from httplib2 import ServerNotFoundError
from httplib import ResponseNotReady
get_credentials(username=user, password=passw, force=True)
user, passw = get_credentials()
user, passw = get_credentials() # TODO
from tempfile import mkdtemp
tmp_dir=mkdtemp()
from pyxnat import Interface
try:
central = Interface(server="%s" % host,
user=user,
password=passw,
cachedir=tmp_dir)
except IndexError:
return "ServerNotFoundError" #TODO Eigene Fehlerklasse
central = Interface(server=host,
user=user,
password=passw,
cachedir=tmp_dir)
except IndexError as e:
raise xsa_errors.ServerNotFoundError("Server not found, check your host-address.") #TODO Ok?
result = []
try:
result = central.select(root_element,search_fields).where(constraints)
except errors.DatabaseError:
return "DatabaseError" #TODO Eigene Fehlerklasse
except errors.DatabaseError as e:
if '401' in str(e):
raise xsa_errors.UnauthorizedError("Unauthorizied attempt. Check your User and Password")
except ServerNotFoundError:
return "ServerNotFoundError" #TODO Eigene Fehlerklasse
raise xsa_errors.ServerNotFoundError("Server not found, check your host-address.")
except ResponseNotReady:
raise xsa_errors.ResponseNotReady("Please check your Host-Address")
if result == []:
raise xsa_errors.QueryError("Please check your query.")
try:
central.disonnect()
......@@ -109,4 +120,5 @@ def search_for(host, root_element, constraints, search_fields, user, passw):
rmtree(tmp_dir)
except:
pass
return result
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment