_exceptions.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """
  2. _exceptions.py
  3. websocket - WebSocket client library for Python
  4. Copyright 2024 engn33r
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. """
  15. class WebSocketException(Exception):
  16. """
  17. WebSocket exception class.
  18. """
  19. pass
  20. class WebSocketProtocolException(WebSocketException):
  21. """
  22. If the WebSocket protocol is invalid, this exception will be raised.
  23. """
  24. pass
  25. class WebSocketPayloadException(WebSocketException):
  26. """
  27. If the WebSocket payload is invalid, this exception will be raised.
  28. """
  29. pass
  30. class WebSocketConnectionClosedException(WebSocketException):
  31. """
  32. If remote host closed the connection or some network error happened,
  33. this exception will be raised.
  34. """
  35. pass
  36. class WebSocketTimeoutException(WebSocketException):
  37. """
  38. WebSocketTimeoutException will be raised at socket timeout during read/write data.
  39. """
  40. pass
  41. class WebSocketProxyException(WebSocketException):
  42. """
  43. WebSocketProxyException will be raised when proxy error occurred.
  44. """
  45. pass
  46. class WebSocketBadStatusException(WebSocketException):
  47. """
  48. WebSocketBadStatusException will be raised when we get bad handshake status code.
  49. """
  50. def __init__(
  51. self,
  52. message: str,
  53. status_code: int,
  54. status_message=None,
  55. resp_headers=None,
  56. resp_body=None,
  57. ):
  58. super().__init__(message)
  59. self.status_code = status_code
  60. self.resp_headers = resp_headers
  61. self.resp_body = resp_body
  62. class WebSocketAddressException(WebSocketException):
  63. """
  64. If the websocket address info cannot be found, this exception will be raised.
  65. """
  66. pass