forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
50 lines (31 loc) · 1.34 KB
/
errors.py
File metadata and controls
50 lines (31 loc) · 1.34 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
from dataclasses import dataclass
from enum import Enum
from typing import Optional
__all__ = ["ErrorLevel", "GeneratorError", "ParseError", "PropertyError", "ValidationError", "ParameterError"]
from pydantic import BaseModel
class ErrorLevel(Enum):
"""The level of an error"""
WARNING = "WARNING" # Client is still generated but missing some pieces
ERROR = "ERROR" # Client could not be generated
@dataclass
class GeneratorError:
"""Base data struct containing info on an error that occurred"""
detail: Optional[str] = None
level: ErrorLevel = ErrorLevel.ERROR
header: str = "Unable to generate the client"
@dataclass
class ParseError(GeneratorError):
"""An error raised when there's a problem parsing an OpenAPI document"""
level: ErrorLevel = ErrorLevel.WARNING
data: Optional[BaseModel] = None
header: str = "Unable to parse this part of your OpenAPI document: "
@dataclass
class PropertyError(ParseError):
"""Error raised when there's a problem creating a Property"""
header = "Problem creating a Property: "
@dataclass
class ParameterError(ParseError):
"""Error raised when there's a problem creating a Parameter."""
header = "Problem creating a Parameter: "
class ValidationError(Exception):
"""Used internally to exit quickly from property parsing due to some internal exception."""