CMS 3D CMS Logo

errors.py
Go to the documentation of this file.
1 """
2 
3 File that contains errors that can occur in CondDBFW.
4 
5 """
6 
7 import traceback
8 import json
9 import base64
10 
11 # not needed - since no more retries is the same as this
13  def __init__(self, server_name):
14  self.server_name = server_name
15 
16  def __str__(self):
17  return "The server '%s' was not found." % self.server_name
18 
20  def __init__(self, retry_limit):
21  self.retry_limit = retry_limit
22 
23  def __str__(self):
24  return "Ran out of retries for contacting the server, where the limit was %d" % self.retry_limit
25 
26 # decorator to check response for error messages - if it contains an error message, throw the appropriate exception
27 def check_response(check="json"):
28 
29  def checker(function):
30 
31  def function_with_exception(self, *args, **kwargs):
32  return_value = None
33  try:
34  return_value = function(self, *args, **kwargs)
35  if check == "json":
36  dictionary = json.loads(return_value)
37  return dictionary
38  elif check == "base64":
39  return base64.b64decode(str(return_value))
40  else:
41  return return_value
42  except (ValueError, TypeError) as e:
43  # the server response couldn't be decoded, so write the log file data to file, and exit
44  self._outputter.write("Couldn't decode response in function '%s' - this is a fault on the server side. Response is:" % function.__name__)
45  self._outputter.write(return_value)
46  self.write_server_side_log(self._log_data)
47  exit()
48  # no need to catch any other exceptions, since this is left to the method that calls 'function'
49 
50  function_with_exception.__doc__ = function.__doc__
51 
52  return function_with_exception
53 
54  return checker
def __init__(self, retry_limit)
Definition: errors.py:20
def check_response(check="json")
Definition: errors.py:27
def __init__(self, server_name)
Definition: errors.py:13
#define str(s)
def exit(msg="")