# Path: sevenbridges/errors.py
# class BadRequest(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=400, message=message, more_info=more_info)
# 
# class Unauthorized(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=401, message=message, more_info=more_info
#         )
# 
# class Forbidden(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=403, message=message, more_info=more_info
#         )
# 
# class NotFound(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=404, message=message, more_info=more_info
#         )
# 
# class MethodNotAllowed(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=405, message=message, more_info=more_info
#         )
# 
# class RequestTimeout(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=408, message=message, more_info=more_info
#         )
# 
# class Conflict(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=409, message=message, more_info=more_info
#         )
# 
# class TooManyRequests(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=429, message=message, more_info=more_info
#         )
# 
# class SbgError(Exception):
#     """Base class for SBG errors.
# 
#     Provides a base exception for all errors
#     that are thrown by sevenbridges-python library.
#     """
# 
#     def __init__(self, message=None, code=None, status=None, more_info=None):
#         """
#         :param code: Custom error code
#         :param status: Http status code.
#         :param message: Message describing the error.
#         """
#         self.code = code
#         self.status = status
#         self.message = message
#         self.more_info = more_info
# 
#     def __str__(self):
#         return str(self.message)
# 
# class ServerError(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=500, message=message, more_info=more_info
#         )
# 
# class ServiceUnavailable(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=503, message=message, more_info=more_info
#         )
# 
# class NonJSONResponseError(SbgError):
#     def __init__(self, status, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=status, message=message, more_info=more_info
#         )


import copy
import logging
import functools
import requests
from json import JSONDecodeError
from sevenbridges.errors import (
    BadRequest, Unauthorized, Forbidden, NotFound, MethodNotAllowed,
    RequestTimeout, Conflict, TooManyRequests, SbgError, ServerError,
    ServiceUnavailable, NonJSONResponseError
)

def check_for_error(func):
    """
    Executes the wrapped function and inspects the response object
    for specific errors.
    """

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            response = func(*args, **kwargs)
        except requests.RequestException as e:
            raise SbgError(message=str(e))
        try:
            status_code = response.status_code
            if status_code in range(200, 204):
                return response
            if status_code == 204:
                return
            e = {
                400: BadRequest,
                401: Unauthorized,
                403: Forbidden,
                404: NotFound,
                405: MethodNotAllowed,
                408: RequestTimeout,
                409: Conflict,
                429: TooManyRequests,
                500: ServerError,
                503: ServiceUnavailable,

# Path: sevenbridges/errors.py
# class BadRequest(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=400, message=message, more_info=more_info)
# 
# class Unauthorized(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=401, message=message, more_info=more_info
#         )
# 
# class Forbidden(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=403, message=message, more_info=more_info
#         )
# 
# class NotFound(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=404, message=message, more_info=more_info
#         )
# 
# class MethodNotAllowed(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=405, message=message, more_info=more_info
#         )
# 
# class RequestTimeout(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=408, message=message, more_info=more_info
#         )
# 
# class Conflict(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=409, message=message, more_info=more_info
#         )
# 
# class TooManyRequests(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=429, message=message, more_info=more_info
#         )
# 
# class SbgError(Exception):
#     """Base class for SBG errors.
# 
#     Provides a base exception for all errors
#     that are thrown by sevenbridges-python library.
#     """
# 
#     def __init__(self, message=None, code=None, status=None, more_info=None):
#         """
#         :param code: Custom error code
#         :param status: Http status code.
#         :param message: Message describing the error.
#         """
#         self.code = code
#         self.status = status
#         self.message = message
#         self.more_info = more_info
# 
#     def __str__(self):
#         return str(self.message)
# 
# class ServerError(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=500, message=message, more_info=more_info
#         )
# 
# class ServiceUnavailable(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=503, message=message, more_info=more_info
#         )
# 
# class NonJSONResponseError(SbgError):
#     def __init__(self, status, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=status, message=message, more_info=more_info
#         )


# Path: sevenbridges/decorators.py
import copy
import logging
import functools
import requests
from json import JSONDecodeError
from sevenbridges.errors import (
    BadRequest, Unauthorized, Forbidden, NotFound, MethodNotAllowed,
    RequestTimeout, Conflict, TooManyRequests, SbgError, ServerError,
    ServiceUnavailable, NonJSONResponseError
)


def check_for_error(func):
    """
    Executes the wrapped function and inspects the response object
    for specific errors.
    """

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            response = func(*args, **kwargs)
        except requests.RequestException as e:
            raise SbgError(message=str(e))
        try:
            status_code = response.status_code
            if status_code in range(200, 204):
                return response
            if status_code == 204:
                return
            e = {
                400: BadRequest,
                401: Unauthorized,
                403: Forbidden,
                404: NotFound,
                405: MethodNotAllowed,
                408: RequestTimeout,
                409: Conflict,
                429: TooManyRequests,
                500: ServerError,
                503: ServiceUnavailable,

            }.get(status_code, SbgError)()