self.detail = detail
self.headers = headers
+ def __str__(self) -> str:
+ return f"{self.status_code}: {self.detail}"
+
def __repr__(self) -> str:
class_name = self.__class__.__name__
return f"{class_name}(status_code={self.status_code!r}, detail={self.detail!r})"
self.code = code
self.reason = reason or ""
+ def __str__(self) -> str:
+ return f"{self.code}: {self.reason}"
+
def __repr__(self) -> str:
class_name = self.__class__.__name__
return f"{class_name}(code={self.code!r}, reason={self.reason!r})"
assert response.text == ""
+def test_http_str():
+ assert str(HTTPException(status_code=404)) == "404: Not Found"
+ assert str(HTTPException(404, "Not Found: foo")) == "404: Not Found: foo"
+ assert str(HTTPException(404, headers={"key": "value"})) == "404: Not Found"
+
+
def test_http_repr():
assert repr(HTTPException(404)) == (
"HTTPException(status_code=404, detail='Not Found')"
)
+def test_websocket_str():
+ assert str(WebSocketException(1008)) == "1008: "
+ assert str(WebSocketException(1008, "Policy Violation")) == "1008: Policy Violation"
+
+
def test_websocket_repr():
assert repr(WebSocketException(1008, reason="Policy Violation")) == (
"WebSocketException(code=1008, reason='Policy Violation')"