def deserialize_return(res, deserializer=None, response=None): '''Returns data deserialized and biiresponse object or raises an exception with biiresponse info''' exc_kls = getExceptionFromHttpError(res.status_code) logger.debug("Exception to throw for this return: %s" % str(exc_kls)) logger.debug("Content Type: %s" % str(res.headers.get('content-type', ""))) #logger.debug("Response: %s" % str(res.content)) data = BiiRestApiClient.decode_return_content(res, response) if exc_kls is None: if deserializer is not None: try: return deserializer.deserialize(data) except KeyError: # TODO: Check if better capture any exception raise BiiServiceException("Error handling server response") else: return data else: if 'content-type' in res.headers and "text/html" in res.headers['content-type']: logger.debug("Can't process html as output") raise exc_kls(data)
def deserialize_return(res, deserializer=None, response=None): '''Returns data deserialized and biiresponse object or raises an exception with biiresponse info''' exc_kls = getExceptionFromHttpError(res.status_code) logger.debug("Exception to throw for this return: %s" % str(exc_kls)) logger.debug("Content Type: %s" % str(res.headers.get('content-type', ""))) #logger.debug("Response: %s" % str(res.content)) data = BiiRestApiClient.decode_return_content(res, response) if exc_kls is None: if deserializer is not None: try: return deserializer.deserialize(data) except KeyError: # TODO: Check if better capture any exception raise BiiServiceException("Error handling server response") else: return data else: if 'content-type' in res.headers and "text/html" in res.headers[ 'content-type']: logger.debug("Can't process html as output") raise exc_kls(data)
def test_get_exception_from_http_error(self): self.assertEquals(getExceptionFromHttpError(404), NotFoundException) self.assertEquals(getExceptionFromHttpError(409), BiiRequestErrorException) self.assertEquals(getExceptionFromHttpError(509), ServerInternalErrorException) self.assertEquals(getExceptionFromHttpError("500"), ServerInternalErrorException) self.assertIsNone(getExceptionFromHttpError(605))