Skip to content

Commit c08df1f

Browse files
committed
Non-issue : Improved error catching in WsServer
1 parent 9ae4757 commit c08df1f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/Network/Websocket/WsServer.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,21 @@ public function handleMessage(NetworkConnectionInterface $conn, NetworkMessageIn
135135
return;
136136
}
137137

138-
if ($conn->WebSocket->established === true)
138+
if ($conn->WebSocket->established === false)
139139
{
140-
$conn->WebSocket->version->wsMessage($this->connCollection[$conn], $message);
141-
return;
140+
return $this->attemptUpgrade($conn);
142141
}
143142

144-
$this->attemptUpgrade($conn);
143+
try
144+
{
145+
return $conn->WebSocket->version->wsMessage($this->connCollection[$conn], $message);
146+
}
147+
catch (Error $ex)
148+
{}
149+
catch (Exception $ex)
150+
{}
151+
152+
$this->handleError($conn, $ex);
145153
}
146154

147155
/**
@@ -156,7 +164,7 @@ public function handleError(NetworkConnectionInterface $conn, $ex)
156164
}
157165
else
158166
{
159-
$conn->close();
167+
$this->close($conn, 500);
160168
}
161169
}
162170

@@ -201,7 +209,16 @@ protected function attemptUpgrade(NetworkConnectionInterface $conn)
201209

202210
$upgraded->WebSocket->established = true;
203211

204-
$this->wsServer->handleConnect($upgraded);
212+
try
213+
{
214+
return $this->wsServer->handleConnect($upgraded);
215+
}
216+
catch (Error $ex)
217+
{}
218+
catch (Exception $ex)
219+
{}
220+
221+
$this->close($conn, 500);
205222
}
206223

207224
/**

0 commit comments

Comments
 (0)