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