1
1
import typing as t
2
2
3
- from pydantic import Field , root_validator , validator
3
+ from pydantic import Field , validator
4
4
from pydantic .json import ENCODERS_BY_TYPE as encoders_by_type
5
+ from starlette .exceptions import HTTPException as StarletteHTTPException
5
6
from starlette .websockets import WebSocketClose
6
7
7
8
from ellar .constants import DEFAULT_LOGGING as default_logging , LOG_LEVELS as log_levels
8
9
from ellar .core .response import JSONResponse , PlainTextResponse
9
10
from ellar .core .versioning import DefaultAPIVersioning
10
- from ellar .exceptions import (
11
- APIException ,
12
- HTTPException as StarletteHTTPException ,
13
- RequestValidationError ,
14
- )
15
11
from ellar .serializer import Serializer , SerializerFilter
16
12
from ellar .types import ASGIApp , TReceive , TScope , TSend
17
13
18
- from ..exception_handlers import (
19
- api_exception_handler ,
20
- request_validation_exception_handler ,
14
+ from .mixins import (
15
+ ConfigDefaultTypesMixin ,
16
+ TEventHandler ,
17
+ TExceptionHandler ,
18
+ TMiddleware ,
19
+ TVersioning ,
21
20
)
22
- from .mixins import ConfigDefaultTypesMixin , TEventHandler , TMiddleware , TVersioning
23
21
24
22
if t .TYPE_CHECKING : # pragma: no cover
25
23
from ellar .core .main import App
@@ -95,14 +93,7 @@ class Config:
95
93
96
94
MIDDLEWARE : t .List [TMiddleware ] = []
97
95
98
- _APP_EXCEPTION_HANDLERS : t .Dict [t .Union [int , t .Type [Exception ]], t .Callable ] = {
99
- RequestValidationError : request_validation_exception_handler ,
100
- APIException : api_exception_handler ,
101
- }
102
-
103
- USER_CUSTOM_EXCEPTION_HANDLERS : t .Dict [
104
- t .Union [int , t .Type [Exception ]], t .Callable
105
- ] = {}
96
+ EXCEPTION_HANDLERS : t .List [TExceptionHandler ] = [] # type:ignore
106
97
107
98
# Default not found handler
108
99
DEFAULT_NOT_FOUND_HANDLER : ASGIApp = _not_found
@@ -122,8 +113,6 @@ class Config:
122
113
# logging Level
123
114
LOG_LEVEL : t .Optional [log_levels ] = log_levels .info
124
115
125
- MIDDLEWARE_DECORATOR : t .List [TMiddleware ] = []
126
-
127
116
ON_REQUEST_STARTUP : t .List [TEventHandler ] = []
128
117
ON_REQUEST_SHUTDOWN : t .List [TEventHandler ] = []
129
118
@@ -132,23 +121,6 @@ class Config:
132
121
133
122
LOGGING : t .Optional [t .Dict [str , t .Any ]] = None
134
123
135
- @root_validator (pre = False )
136
- def pre_root_validate (cls , values : t .Any ) -> t .Any :
137
- app_exception_handlers = dict (cls ._APP_EXCEPTION_HANDLERS )
138
- user_custom_exception_handlers = values .get (
139
- "USER_CUSTOM_EXCEPTION_HANDLERS" , {}
140
- )
141
-
142
- app_exception_handlers .update (** user_custom_exception_handlers )
143
-
144
- values ["EXCEPTION_HANDLERS" ] = app_exception_handlers
145
- middleware_decorator_handlers = list (values .get ("MIDDLEWARE_DECORATOR" , []))
146
- user_settings_middleware = list (values .get ("MIDDLEWARE" , []))
147
- middleware_decorator_handlers .extend (user_settings_middleware )
148
- values ["MIDDLEWARE" ] = middleware_decorator_handlers
149
-
150
- return values
151
-
152
124
@validator ("MIDDLEWARE" , pre = True )
153
125
def pre_middleware_validate (cls , value : t .Any ) -> t .Any :
154
126
if isinstance (value , tuple ):
0 commit comments