codekingpro/portable-devtools
115k
1"""2_exceptions.py3websocket - WebSocket client library for Python4 5Copyright 2025 engn33r6 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 at10 11 http://www.apache.org/licenses/LICENSE-2.012 13Unless required by applicable law or agreed to in writing, software14distributed 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 and17limitations under the License.18"""19 20 21class WebSocketException(Exception):22 """23 WebSocket exception class.24 """25 26 pass27 28 29class WebSocketProtocolException(WebSocketException):30 """31 If the WebSocket protocol is invalid, this exception will be raised.32 """33 34 pass35 36 37class WebSocketPayloadException(WebSocketException):38 """39 If the WebSocket payload is invalid, this exception will be raised.40 """41 42 pass43 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 pass52 53 54class WebSocketTimeoutException(WebSocketException):55 """56 WebSocketTimeoutException will be raised at socket timeout during read/write data.57 """58 59 pass60 61 62class WebSocketProxyException(WebSocketException):63 """64 WebSocketProxyException will be raised when proxy error occurred.65 """66 67 pass68 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_code85 self.resp_headers = resp_headers86 self.resp_body = resp_body87 88 89class WebSocketAddressException(WebSocketException):90 """91 If the websocket address info cannot be found, this exception will be raised.92 """93 94 pass95 