_exceptions.py 2.1 KB

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