1"""
2This module defines error handlers, operations that produce proper response problems.
3"""
4
5import logging
6
7from .exceptions import ResolverProblem
8
9logger = logging.getLogger("connexion.handlers")
10
11RESOLVER_ERROR_ENDPOINT_RANDOM_DIGITS = 6
12
13
14class ResolverErrorHandler:
15 """
16 Handler for responding to ResolverError.
17 """
18
19 def __init__(self, status_code, exception):
20 self.status_code = status_code
21 self.exception = exception
22
23 @property
24 def function(self):
25 return self.handle
26
27 def handle(self, *args, **kwargs):
28 raise ResolverProblem(
29 detail=self.exception.args[0],
30 status=self.status_code,
31 )
32
33 @property
34 def operation_id(self):
35 return "noop"
36
37 @property
38 def randomize_endpoint(self):
39 return RESOLVER_ERROR_ENDPOINT_RANDOM_DIGITS
40
41 def get_path_parameter_types(self):
42 return {}
43
44 @property
45 def uri_parser_class(self):
46 return "dummy"
47
48 @property
49 def api(self):
50 return "dummy"
51
52 def get_mimetype(self):
53 return "dummy"
54
55 async def __call__(self, *args, **kwargs):
56 raise ResolverProblem(
57 detail=self.exception.args[0],
58 status=self.status_code,
59 )