from table_manager_api.dto.exception import TableError


class UnknownError(TableError):
    def __init__(
        self,       # type: UnknownError
        token,      # type: int
        data,       # type: bytes
    ):
        self.token = token
        try:
            self.message = data.decode()
        except UnicodeDecodeError:
            self.message = data.hex()

    def get_extra_data(self):
        return {
            "token": self.token,
            "data": self.message
        }

    def __str__(self):
        return "token: {}, data: {}".format(self.token, self.message)
