def validate_response(called_method: Callable) -> Callable:
"""Decorator for HTTPClient validating received response for REST API methods.
If status code from server is different than 200 raises HTTPError.
:param called_method: requests methods - POST, GET, PUT, PATH, DELETE
:return: response from server
"""
def wrapper(method: Callable, endpoint: str, *args: List[Any], **kwargs: Dict[Any, Any]) -> Response:
"""Executes decorated function and checks status_code."""
resp = called_method(method, endpoint, *args, **kwargs)
if resp.status_code != 200:
logging.error('HTTP Client returned status code %s for url %s', resp.status_code, resp.url)
raise HTTPError('HTTP Client returned status code {0} for url {1}'.format(str(resp.status_code), resp.url))
return resp
return wrapper
评论列表
文章目录