Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:type timeout: float
:return: Depends on the value of also_return_response sent in
to the constructor.
"""
incoming_response = self._get_incoming_response(timeout)
swagger_result = self._get_swagger_result(incoming_response)
if self.operation is not None:
if self.request_config.also_return_response:
return swagger_result, incoming_response
return swagger_result
if 200 <= incoming_response.status_code < 300:
return incoming_response
raise make_http_exception(response=incoming_response)
def raise_on_expected(http_response):
# type: (IncomingResponse) -> None
"""Raise an HTTPError if the response is non-2XX and matches a response
in the swagger spec.
:param http_response: :class:`bravado_core.response.IncomingResponse`
:raises: HTTPError
"""
if not 200 <= http_response.status_code < 300:
raise make_http_exception(
response=http_response,
swagger_result=http_response.swagger_result)
- On 5XX status code, the HTTPError has minimal information.
- On non-2XX status code with no matching response, the HTTPError
contains a detailed error message.
- On non-2XX status code with a matching response, the HTTPError
contains the return value.
"""
response_callbacks = response_callbacks or []
try:
raise_on_unexpected(incoming_response)
incoming_response.swagger_result = unmarshal_response_inner(
response=incoming_response,
op=operation,
)
except MatchingResponseNotFound as e:
exception = make_http_exception(
response=incoming_response,
message=str(e)
)
six.reraise(
type(exception),
exception,
sys.exc_info()[2])
finally:
# Always run the callbacks regardless of success/failure
for response_callback in response_callbacks:
response_callback(incoming_response, operation)
raise_on_expected(incoming_response)
def raise_on_unexpected(http_response):
# type: (IncomingResponse) -> None
"""Raise an HTTPError if the response is 5XX.
:param http_response: :class:`bravado_core.response.IncomingResponse`
:raises: HTTPError
"""
if 500 <= http_response.status_code <= 599:
raise make_http_exception(response=http_response)