File indexing completed on 2024-04-06 12:01:53
0001 """
0002
0003 File that contains errors that can occur in CondDBFW.
0004
0005 """
0006
0007 import traceback
0008 import json
0009 import base64
0010
0011
0012 class ServerNotFoundException(Exception):
0013 def __init__(self, server_name):
0014 self.server_name = server_name
0015
0016 def __str__(self):
0017 return "The server '%s' was not found." % self.server_name
0018
0019 class NoMoreRetriesException(Exception):
0020 def __init__(self, retry_limit):
0021 self.retry_limit = retry_limit
0022
0023 def __str__(self):
0024 return "Ran out of retries for contacting the server, where the limit was %d" % self.retry_limit
0025
0026
0027 def check_response(check="json"):
0028
0029 def checker(function):
0030
0031 def function_with_exception(self, *args, **kwargs):
0032 return_value = None
0033 try:
0034 return_value = function(self, *args, **kwargs)
0035 if check == "json":
0036 dictionary = json.loads(return_value)
0037 return dictionary
0038 elif check == "base64":
0039 return base64.b64decode(str(return_value))
0040 else:
0041 return return_value
0042 except (ValueError, TypeError) as e:
0043
0044 self._outputter.write("Couldn't decode response in function '%s' - this is a fault on the server side. Response is:" % function.__name__)
0045 self._outputter.write(return_value)
0046 self.write_server_side_log(self._log_data)
0047 exit()
0048
0049
0050 function_with_exception.__doc__ = function.__doc__
0051
0052 return function_with_exception
0053
0054 return checker