示例#1
0
 def getUnifiedRPCError(self, response):
     """Get unifiedrpc error from response
     """
     # HTTP 200
     if response.status_code in (200, 201, 202):
         return
     # Find error from error mapping
     initKwargs = {}
     errorClass = self.mapping.get(response.status_code)
     if not errorClass:
         # OK, error class not found
         errorClass = UnhandledHttpError
         initKwargs['httpStatusCode'] = response.status_code
     # Try to decode the content as standard error
     # TODO: Support handling more response content format
     # Try to get error from header
     if 'X-SERVER-ERROR' in response.headers:
         # Load from header
         try:
             error = json.loads(response.headers['X-SERVER-ERROR'])
             if error.get('code'):
                 initKwargs['code'] = error['code']
             if error.get('reason'):
                 initKwargs['reason'] = error['reason']
             if error.get('detail'):
                 initKwargs['detail'] = error['detail']
         except:
             if self.logger.isEnabledFor(logging.DEBUG):
                 self.logger.exception('Failed to load error content, skip')
     else:
         # Load from content
         try:
             error = json.loads(response.content)
             if error.get('code'):
                 initKwargs['code'] = error['code']
             if error.get('reason'):
                 initKwargs['reason'] = error['reason']
             if error.get('detail'):
                 initKwargs['detail'] = error['detail']
         except:
             if self.logger.isEnabledFor(logging.DEBUG):
                 self.logger.exception('Failed to load error content, skip')
     # Done
     return errorClass(**initKwargs)
示例#2
0
 def getUnifiedRPCError(self, response):
     """Get unifiedrpc error from response
     """
     # HTTP 200
     if response.status_code in (200, 201, 202):
         return
     # Find error from error mapping
     initKwargs = {}
     errorClass = self.mapping.get(response.status_code)
     if not errorClass:
         # OK, error class not found
         errorClass = UnhandledHttpError
         initKwargs['httpStatusCode'] = response.status_code
     # Try to decode the content as standard error
     # TODO: Support handling more response content format
     # Try to get error from header
     if 'X-SERVER-ERROR' in response.headers:
         # Load from header
         try:
             error = json.loads(response.headers['X-SERVER-ERROR'])
             if error.get('code'):
                 initKwargs['code'] = error['code']
             if error.get('reason'):
                 initKwargs['reason'] = error['reason']
             if error.get('detail'):
                 initKwargs['detail'] = error['detail']
         except:
             if self.logger.isEnabledFor(logging.DEBUG):
                 self.logger.exception('Failed to load error content, skip')
     else:
         # Load from content
         try:
             error = json.loads(response.content)
             if error.get('code'):
                 initKwargs['code'] = error['code']
             if error.get('reason'):
                 initKwargs['reason'] = error['reason']
             if error.get('detail'):
                 initKwargs['detail'] = error['detail']
         except:
             if self.logger.isEnabledFor(logging.DEBUG):
                 self.logger.exception('Failed to load error content, skip')
     # Done
     return errorClass(**initKwargs)
示例#3
0
 def __init__(self, dictObject = None):
     """Create a new DictSession
     """
     self._changed = False
     if dictObject is None:
         self.dictObject = {}
     elif isinstance(dictObject, basestring):
         self.dictObject = json.loads(b64decode(dictObject).decode('utf8'))
     else:
         self.dictObject = dictObject
示例#4
0
 def __init__(self, dictObject=None):
     """Create a new DictSession
     """
     self._changed = False
     if dictObject is None:
         self.dictObject = {}
     elif isinstance(dictObject, basestring):
         self.dictObject = json.loads(b64decode(dictObject).decode('utf8'))
     else:
         self.dictObject = dictObject