MCPcopy
hub / github.com/sanic-org/sanic / SanicException

Class SanicException

sanic/exceptions.py:20–98  ·  view source on GitHub ↗

Generic exception that will generate an HTTP response when raised in the context of a request lifecycle. Usually, it is best practice to use one of the more specific exceptions than this generic one. Even when trying to raise a 500, it is generally preferable to use `ServerError`.

Source from the content-addressed store, hash-verified

18
19
20class SanicException(Exception):
21 """Generic exception that will generate an HTTP response when raised in the context of a request lifecycle.
22
23 Usually, it is best practice to use one of the more specific exceptions
24 than this generic one. Even when trying to raise a 500, it is generally
25 preferable to use `ServerError`.
26
27 Args:
28 message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`,
29 then the appropriate HTTP response status message will be used instead. Defaults to `None`.
30 status_code (Optional[int], optional): The HTTP response code to send, if applicable. If `None`,
31 then it will be 500. Defaults to `None`.
32 quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed from the logs.
33 Defaults to `None`.
34 context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
35 sent to the client upon exception. Defaults to `None`.
36 extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
37 sent to the client when in PRODUCTION mode. Defaults to `None`.
38 headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
39 response. Defaults to `None`.
40
41 Examples:
42 ```python
43 raise SanicException(
44 "Something went wrong",
45 status_code=999,
46 context={
47 "info": "Some additional details to send to the client",
48 },
49 headers={
50 "X-Foo": "bar"
51 }
52 )
53 ```
54 """ # noqa: E501
55
56 status_code: int = 500
57 quiet: bool | None = False
58 headers: dict[str, str] = {}
59 message: str = ""
60
61 def __init__(
62 self,
63 message: str | bytes | None = None,
64 status_code: int | None = None,
65 *,
66 quiet: bool | None = None,
67 context: dict[str, Any] | None = None,
68 extra: dict[str, Any] | None = None,
69 headers: dict[str, str] | None = None,
70 ) -> None:
71 self.context = context
72 self.extra = extra
73 status_code = status_code or getattr(
74 self.__class__, "status_code", None
75 )
76 quiet = (
77 quiet

Callers 15

create_simple_serverFunction · 0.90
check_error_formatFunction · 0.90
__init__Method · 0.90
loopMethod · 0.90
get_taskMethod · 0.90
register_appMethod · 0.90
unregister_appMethod · 0.90
get_appMethod · 0.90
_server_eventMethod · 0.90
inspectorMethod · 0.90
managerMethod · 0.90
appsMethod · 0.90

Calls

no outgoing calls

Tested by 8

check_supportedMethod · 0.72
testFunction · 0.72
has_sugarFunction · 0.72
handler_401_errorFunction · 0.72
handler_500_errorFunction · 0.72
handler_abort_messageFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…