Commit 557c7de7 authored by Vadzim Kulyba (EPAM)'s avatar Vadzim Kulyba (EPAM) Committed by harshit aggarwal
Browse files

feat(azure): add request raiser decorator

parent a50708bf
# Copyright © Microsoft Corporation
# Copyright 2021 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utils for request managment library."""
import logging
from typing import Callable
import requests
logger = logging.getLogger()
def request_raiser(request_function: Callable) -> Callable:
"""
Wrap a request function and check response. If response is not ok
then raises HTTPError
request_function(*args, **kwargs) -> requests.Response
"""
def _wrapper(*args, **kwargs) -> requests.Response:
response = request_function(*args, **kwargs)
if not response.ok:
try:
response.raise_for_status()
except requests.HTTPError as e:
logger.error(f"{response.text}")
raise e
return response
return _wrapper
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment