-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.py
More file actions
66 lines (43 loc) · 1.49 KB
/
errors.py
File metadata and controls
66 lines (43 loc) · 1.49 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
61
62
63
64
65
66
from typing import TypedDict
class AuthenticationError(Exception):
"""Raised when there is an authentication error."""
pass
class MissingApiToken(Exception):
"""Raised when an API token is missing."""
pass
class UnknownRpcMethod(Exception):
"""Raised when an unknown RPC method is called."""
pass
class ProcessAlreadyExited(Exception):
"""Raised when trying to interact with a process that has already exited."""
pass
class HTTPStatusError(Exception):
"""Raised when an HTTP request returns a non-success status code."""
def __init__(
self,
status_code: int,
message: str,
code: str = "UNKNOWN_ERROR",
trace_id: str | None = None,
) -> None:
self.status_code = status_code
self.message = message
self.code = code
self.trace_id = trace_id
detail = f"status: {status_code}, code: {code}"
if trace_id:
detail += f", traceId: {trace_id}"
super().__init__(f"{message} ({detail})")
class ZodErrorRaw(TypedDict):
expected: str
code: str
path: list[str]
message: str
class RpcValidationError(ValueError):
"""Raised when there is a validation error in RPC parameters."""
def __init__(self, errors: list[ZodErrorRaw]) -> None:
self.errors = errors
msg = "Invalid Parameters:\n"
for err in errors:
msg += f"- Path: {'.'.join(err['path'])}, Expected: {err['expected']}\n"
super().__init__(msg)