Skip to content

Commit fb5401c

Browse files
committed
proxy: Provide clear reason for websocket connection error
Also, the error code seems to have changed from 503 -> 599 Not too sure why, but modifying tests appropriately
1 parent 66282a8 commit fb5401c

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

configurable_http_proxy/handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,12 @@ def write(msg):
400400
self.proxy.timeout, websocket_connect(req, on_message_callback=write)
401401
)
402402
except HTTPClientError as err:
403-
self.set_status(err.code)
403+
self.closed = True
404+
self.set_status(err.code, reason=err.message)
404405
self.write(err.message)
405406
self.finish()
406407
except Exception as err:
408+
self.closed = True
407409
await self.handle_proxy_error(503, err)
408410
raise
409411

configurable_http_proxy_test/test_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_last_activity_not_updated_on_errors_websocket(self):
325325
self.proxy._routes.update("/missing", {"last_activity": now})
326326

327327
# fail a websocket activity
328-
with pytest.raises(HTTPClientError, match="HTTP 503: Service Unavailable"):
328+
with pytest.raises(HTTPClientError, match="HTTP 599: Timeout while connecting"):
329329
yield websocket_connect(self.get_url("/missing/ws").replace("http:", "ws:"))
330330

331331
# expect an error, since there is no websocket handler - check last_activity was not updated

0 commit comments

Comments
 (0)