-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.py
50 lines (41 loc) · 1.31 KB
/
errors.py
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
from typing import Dict
from pydantic import BaseModel
class ErrorDetail(BaseModel):
error: str
msg: str
class ErrorExample(BaseModel):
summary: str
value: ErrorDetail
def to_example_dict(self) -> Dict:
return {
"summary": self.summary,
"value": self.value.dict()
}
class LimitErrorLessThanExample(ErrorExample):
summary = "Limit Error Less Than Example"
value = ErrorDetail(error="ValueError", msg="Can't use limit value under 1")
class LimitErrorMoreThanExample(ErrorExample):
summary = "Limit Error More Than Example"
value = ErrorDetail(error="ValueError", msg="Can't use limit value above 10000")
class NoDataFoundError(ErrorExample):
summary = "No Data Is Returned From Database Example"
value = ErrorDetail(error="TypeError", msg="No such data exists!")
LIMIT_ERROR = {
"content": {
"application/json": {
"examples": {
"limit_error_less": LimitErrorLessThanExample().to_example_dict(),
"limit_error_more": LimitErrorMoreThanExample().to_example_dict()
}
}
}
}
NO_DATA_FOUND_ERROR = {
"content": {
"application/json": {
"examples": {
"no_data_found": NoDataFoundError().to_example_dict()
}
}
}
}