generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathexceptions.py
More file actions
61 lines (42 loc) · 1.68 KB
/
exceptions.py
File metadata and controls
61 lines (42 loc) · 1.68 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
from collections.abc import Sequence
from typing import Any, Literal
class ValidationException(Exception):
"""
Base exception for all validation errors
"""
def __init__(self, errors: Sequence[Any]) -> None:
self._errors = errors
def errors(self) -> Sequence[Any]:
return self._errors
class RequestValidationError(ValidationException):
"""
Raised when the request body does not match the OpenAPI schema
"""
def __init__(self, errors: Sequence[Any], *, body: Any = None) -> None:
super().__init__(errors)
self.body = body
class ResponseValidationError(ValidationException):
"""
Raised when the response body does not match the OpenAPI schema
"""
def __init__(self, errors: Sequence[Any], *, body: Any = None, source: Literal["route", "app"] = "app") -> None:
super().__init__(errors)
self.body = body
self.source = source
class SerializationError(Exception):
"""
Base exception for all encoding errors
"""
class SchemaValidationError(ValidationException):
"""
Raised when the OpenAPI schema validation fails
"""
class OpenAPIMergeError(Exception):
"""Exception raised when there's a conflict during OpenAPI merge."""
class RequestUnsupportedContentType(NotImplementedError, ValidationException):
"""Exception raised when trying to read request body data, with unknown headers"""
# REVIEW: This inheritance is for backwards compatibility.
# Just inherit from ValidationException in Powertools V4
def __init__(self, msg: str, errors: Sequence[Any]) -> None:
NotImplementedError.__init__(self, msg)
ValidationException.__init__(self, errors)