Coverage for nexios\exceptions.py: 72%
25 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-21 20:31 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-21 20:31 +0100
1from __future__ import annotations
2import http
3import typing
6class HTTPException(Exception):
7 def __init__(
8 self,
9 status_code: int,
10 detail: typing.Optional[typing.Any] = None,
11 headers: typing.Dict[str, typing.Any] = {},
12 ) -> None:
13 super().__init__(detail or http.HTTPStatus(status_code).phrase)
14 self.status_code = status_code
15 self.detail = self.args[0]
16 self.headers = headers
18 def __str__(self) -> str:
19 return f"HTTP {self.status_code}: {self.detail}"
21 def __repr__(self) -> str:
22 return f"{self.__class__.__name__}({self.status_code}, {self.detail!r})"
25class NotFoundException(HTTPException):
26 def __init__(
27 self,
28 detail: typing.Optional[str] = None,
29 headers: typing.Dict[str, typing.Any] = {},
30 ) -> None:
31 super().__init__(status_code=404, detail=detail or "Not Found", headers=headers)
34class WebSocketException(Exception):
35 def __init__(self, code: int, reason: typing.Optional[str] = None) -> None:
36 super().__init__(reason or "")
37 self.code = code
38 self.reason = self.args[0]
40 def __str__(self) -> str:
41 return f"WebSocket {self.code}: {self.reason}"
43 def __repr__(self) -> str:
44 return f"{self.__class__.__name__}({self.code}, {self.reason!r})"