"""HTTP related errors"""

from sap.errors import SAPCliError


class HTTPRequestError(SAPCliError):
    """Exception for unexpected HTTP responses"""

    def __init__(self, request, response):
        super().__init__()

        self.request = request
        self.response = response

    def __repr__(self):
        return f'{self.response.status_code}\n{self.response.text}'

    def __str__(self):
        return repr(self)


class UnauthorizedError(SAPCliError):
    """Exception for unauthorized """

    def __init__(self, request, response, user):
        super().__init__()

        self.request = request
        self.response = response
        self.method = request.method
        self.url = request.url
        self.user = user

    def __repr__(self):
        return f'Authorization for the user "{self.user}" has failed: {self.method} {self.url}'

    def __str__(self):
        return repr(self)


class TimedOutRequestError(SAPCliError):
    """Exception for timeout requests"""

    def __init__(self, request, timeout):
        super().__init__()

        self.request = request
        self.method = request.method
        self.url = request.url
        self.timeout = timeout

    def __repr__(self):
        return f'The request {self.method} {self.url} took more than {self.timeout}s'

    def __str__(self):
        return repr(self)

"""HTTP related errors"""

from sap.errors import SAPCliError


class HTTPRequestError(SAPCliError):
    """Exception for unexpected HTTP responses"""

    def __init__(self, request, response):
        super().__init__()

        self.request = request
        self.response = response

    def __repr__(self):
        return f'{self.response.status_code}\n{self.response.text}'

    def __str__(self):
        return repr(self)


class UnauthorizedError(SAPCliError):
    """Exception for unauthorized """

    def __init__(self, request, response, user):
        super().__init__()

        self.request = request
        self.response = response
        self.method = request.method
        self.url = request.url
        self.user = user

    def __repr__(self):
        return f'Authorization for the user "{self.user}" has failed: {self.method} {self.url}'

    def __str__(self):
        return repr(self)


class TimedOutRequestError(SAPCliError):
    """Exception for timeout requests"""

    def __init__(self, request, timeout):
        super().__init__()

        self.request = request
        self.method = request.method
        self.url = request.url
        self.timeout = timeout

    def __repr__(self):
        return f'The request {self.method} {self.url} took more than {self.timeout}s'

    def __str__(self):
        return repr(self)

HTTP related errors Exception for unexpected HTTP responses Exception for unauthorized Exception for timeout requests