-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
85 lines (64 loc) · 2.35 KB
/
Copy pathexceptions.py
File metadata and controls
85 lines (64 loc) · 2.35 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Generated by ariadne-codegen
from typing import Any, Dict, List, Optional, Union
import httpx
class GraphQLClientError(Exception):
"""Base exception."""
class GraphQLClientHttpError(GraphQLClientError):
def __init__(self, status_code: int, response: httpx.Response) -> None:
self.status_code = status_code
self.response = response
def __str__(self) -> str:
return f"HTTP status code: {self.status_code}"
class GraphQLClientInvalidResponseError(GraphQLClientError):
def __init__(self, response: httpx.Response) -> None:
self.response = response
def __str__(self) -> str:
return "Invalid response format."
class GraphQLClientGraphQLError(GraphQLClientError):
def __init__(
self,
message: str,
locations: Optional[List[Dict[str, int]]] = None,
path: Optional[List[str]] = None,
extensions: Optional[Dict[str, object]] = None,
orginal: Optional[Dict[str, object]] = None,
):
self.message = message
self.locations = locations
self.path = path
self.extensions = extensions
self.orginal = orginal
def __str__(self) -> str:
return self.message
@classmethod
def from_dict(cls, error: Dict[str, Any]) -> "GraphQLClientGraphQLError":
return cls(
message=error["message"],
locations=error.get("locations"),
path=error.get("path"),
extensions=error.get("extensions"),
orginal=error,
)
class GraphQLClientGraphQLMultiError(GraphQLClientError):
def __init__(
self,
errors: List[GraphQLClientGraphQLError],
data: Optional[Dict[str, Any]] = None,
):
self.errors = errors
self.data = data
def __str__(self) -> str:
return "; ".join(str(e) for e in self.errors)
@classmethod
def from_errors_dicts(
cls, errors_dicts: List[Dict[str, Any]], data: Optional[Dict[str, Any]] = None
) -> "GraphQLClientGraphQLMultiError":
return cls(
errors=[GraphQLClientGraphQLError.from_dict(e) for e in errors_dicts],
data=data,
)
class GraphQLClientInvalidMessageFormat(GraphQLClientError):
def __init__(self, message: Union[str, bytes]) -> None:
self.message = message
def __str__(self) -> str:
return "Invalid message format."