File: exceptions.py

package info (click to toggle)
python-awair 0.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,016 kB
  • sloc: python: 1,041; makefile: 12
file content (46 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
"""Various exceptions for the Awair API."""

from typing import Optional


class AwairError(Exception):
    """Base awair exception class."""

    message = "Error querying the Awair API."

    def __init__(self, extra_message: Optional[str] = None) -> None:
        """Add extra messages to our base message."""
        final_message = self.message
        if extra_message:
            final_message += f" {extra_message}"

        super().__init__(final_message)


class AuthError(AwairError):
    """Some kind of authorization or authentication failure."""

    message = (
        "The supplied access token is invalid or "
        + "does not have access to the requested data"
    )


class QueryError(AwairError):
    """The query was somehow malformed."""

    message = "The supplied parameters were invalid."


class NotFoundError(AwairError):
    """The requested endpoint is gone."""

    message = "The Awair API returned an unexpected HTTP 404."


class RatelimitError(AwairError):
    """The API quota was exceeded."""

    message = (
        "The ratelimit for the Awair API has been " + "exceeded. Please try again later"
    )