-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
60 lines (38 loc) · 1.83 KB
/
Copy pathexceptions.py
File metadata and controls
60 lines (38 loc) · 1.83 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Exceptions raised by the SDK.
The hierarchy mirrors the PHP SDK so that the same API condition carries the
same name in both: a 422 is a validation problem, a 404 is a missing resource,
a 400 is a rejected action.
"""
from __future__ import annotations
from typing import Any
class WaAPIError(Exception):
"""Base class for every error this SDK raises."""
class ValidationError(WaAPIError):
"""The request body failed the API's validation (HTTP 422)."""
def __init__(self, errors: Any) -> None:
super().__init__("The given data failed to pass validation.")
self.errors = errors
class NotFoundError(WaAPIError):
"""The addressed resource does not exist (HTTP 404)."""
def __init__(self, message: str = "The resource you are looking for could not be found.") -> None:
super().__init__(message)
class AuthenticationError(WaAPIError):
"""The API token is missing, wrong or lacks the required scope (HTTP 401/403)."""
class RateLimitError(WaAPIError):
"""Too many requests (HTTP 429)."""
def __init__(self, message: str, retry_after: float | None = None) -> None:
super().__init__(message)
self.retry_after = retry_after
class FailedActionError(WaAPIError):
"""The API accepted the request but did not carry the action out.
This covers two cases that look different on the wire but mean the same
thing to a caller: an HTTP 400, and an HTTP 200 whose body says
``{"status": "error"}``. The second is the dangerous one — it is a
successful HTTP exchange, so code that only checks the status code treats
a message that was never sent as delivered.
"""
def __init__(self, message: str, response: Any = None) -> None:
super().__init__(message)
self.response = response
class ServerError(WaAPIError):
"""The API returned a 5xx."""