Skip to content

Status Classes

Wraps the status code of a response to give some additional context

ResponseStatus

A response status object that can be checked if a request was ok

Source code in async_spotify/api/_response_status.py
class ResponseStatus:
    """
    A response status object that can be checked if a request was ok
    """

    def __init__(self, status_code: int):
        """
        Create a Response status object that translates the status code to a success and message

        Args:
            status_code: A valid http status code
        """

        self.moved = False
        self.success = False
        self.error = False

        if status_code in STATUS_CODES["OK"]:
            self.success = True
            message: str = STATUS_CODES["OK"][status_code][0]

        elif status_code in STATUS_CODES["REDIRECT"]:
            self.moved = True
            message: str = STATUS_CODES["REDIRECT"][status_code][0]

        elif status_code in STATUS_CODES["CLIENT_ERROR"]:
            self.error = True
            message: str = STATUS_CODES["CLIENT_ERROR"][status_code][0]

        elif status_code in STATUS_CODES["SERVER_ERROR"]:
            self.error = True
            message = STATUS_CODES["SERVER_ERROR"][status_code][0]
        else:
            self.error = True
            message: str = "Unknown response code"

        self.code: int = status_code
        self.message: str = message

__init__(self, status_code) special

Create a Response status object that translates the status code to a success and message

Parameters:

Name Type Description Default
status_code int

A valid http status code

required
Source code in async_spotify/api/_response_status.py
def __init__(self, status_code: int):
    """
    Create a Response status object that translates the status code to a success and message

    Args:
        status_code: A valid http status code
    """

    self.moved = False
    self.success = False
    self.error = False

    if status_code in STATUS_CODES["OK"]:
        self.success = True
        message: str = STATUS_CODES["OK"][status_code][0]

    elif status_code in STATUS_CODES["REDIRECT"]:
        self.moved = True
        message: str = STATUS_CODES["REDIRECT"][status_code][0]

    elif status_code in STATUS_CODES["CLIENT_ERROR"]:
        self.error = True
        message: str = STATUS_CODES["CLIENT_ERROR"][status_code][0]

    elif status_code in STATUS_CODES["SERVER_ERROR"]:
        self.error = True
        message = STATUS_CODES["SERVER_ERROR"][status_code][0]
    else:
        self.error = True
        message: str = "Unknown response code"

    self.code: int = status_code
    self.message: str = message

A collection of http response codes and their meaning (copied from python requests)


Last update: August 28, 2020