Skip to content

Errors

deezify.errors

Deezer API exceptions.

Mirrors the error envelope returned by https://api.deezer.com plus transport-level failures. See https://developers.deezer.com/api/errors.

DeezerError

Bases: Exception

Base class for every error raised by this SDK.

Source code in deezify/errors.py
10
11
class DeezerError(Exception):
    """Base class for every error raised by this SDK."""

DeezerAPIError

Bases: DeezerError

The Deezer API answered with an {"error": {...}} envelope.

Source code in deezify/errors.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class DeezerAPIError(DeezerError):
    """The Deezer API answered with an ``{"error": {...}}`` envelope."""

    #: Human readable mapping of documented error codes.
    #: https://developers.deezer.com/api/errors
    CODE_DESCRIPTIONS = {
        4: "Quota exceeded (QUOTA)",
        100: "Items limit exceeded (ITEMS_LIMIT_EXCEEDED)",
        200: "Missing/insufficient permission (PERMISSION)",
        300: "Invalid or expired access token (TOKEN_INVALID)",
        500: "Invalid parameter value (PARAMETER)",
        501: "Missing required parameter (PARAMETER_MISSING)",
        600: "Invalid query (QUERY_INVALID)",
        700: "Service busy, retry later (SERVICE_BUSY)",
        800: "Requested data not found (DATA_NOT_FOUND)",
        901: "Operation not allowed on an individual account "
        "(INDIVIDUAL_ACCOUNT_NOT_ALLOWED)",
    }

    def __init__(
        self,
        error_type: str,
        message: str,
        code: int,
        *,
        status_code: int | None = None,
        endpoint: str | None = None,
    ) -> None:
        self.type = error_type
        self.message = message
        self.code = code
        self.status_code = status_code
        self.endpoint = endpoint
        detail = self.CODE_DESCRIPTIONS.get(code, "")
        hint = f" — {detail}" if detail else ""
        where = f" [{endpoint}]" if endpoint else ""
        super().__init__(f"Deezer API error {code} ({error_type}){where}: {message}{hint}")

    @classmethod
    def from_payload(
        cls, payload: dict, *, status_code: int | None = None, endpoint: str | None = None
    ) -> "DeezerAPIError":
        err = payload.get("error") or {}
        return cls(
            str(err.get("type", "Exception")),
            str(err.get("message", "Unknown Deezer API error")),
            int(err.get("code", 0)),
            status_code=status_code,
            endpoint=endpoint,
        )

DeezerTransportError

Bases: DeezerError

Network / HTTP / decoding failure (no usable API envelope).

Source code in deezify/errors.py
66
67
68
69
70
71
72
73
class DeezerTransportError(DeezerError):
    """Network / HTTP / decoding failure (no usable API envelope)."""

    def __init__(self, message: str, *, status_code: int | None = None) -> None:
        self.message = message
        self.status_code = status_code
        suffix = f" (HTTP {status_code})" if status_code is not None else ""
        super().__init__(f"{message}{suffix}")

DeezerAuthError

Bases: DeezerError

OAuth helper misuse (missing app_id/secret, bad callback payload...).

Source code in deezify/errors.py
76
77
class DeezerAuthError(DeezerError):
    """OAuth helper misuse (missing app_id/secret, bad callback payload...)."""