I better error display

This commit is contained in:
a6a2f5842 2025-06-13 10:31:59 +02:00
parent 4f0dd41028
commit 9e85f2c457
2 changed files with 71 additions and 79 deletions

View File

@ -255,8 +255,7 @@ class Controller
? $trace[0]['line'] ? $trace[0]['line']
: null; : null;
// log Log::channel('websocket')->error('Send error: ' . @$p['data']['message'], $p);
Log::channel('websocket')->error('Send error: ' . $p['data']['message'], $p);
if (get_class($this->connection) === MockConnection::class) { if (get_class($this->connection) === MockConnection::class) {
$connection = clone $this->connection; $connection = clone $this->connection;

View File

@ -84,95 +84,88 @@ class Handler implements MessageComponentInterface
ConnectionInterface $connection, ConnectionInterface $connection,
MessageInterface $message MessageInterface $message
) { ) {
if (! isset($connection->app)) { try {
return; if (! isset($connection->app)) {
} return;
}
request()->server->set('REMOTE_ADDR', $connection->remoteAddress); request()->server->set('REMOTE_ADDR', $connection->remoteAddress);
PusherMessageFactory::createForMessage( PusherMessageFactory::createForMessage(
$message, $message,
$connection, $connection,
$this->channelManager $this->channelManager
)->respond(); )->respond();
// Payload json to array // Payload json to array
$message = json_decode($message->getPayload(), true); $message = json_decode($message->getPayload(), true);
// Cut short for ping pong // Cut short for ping pong
if (strpos($message['event'], ':ping') !== false) { if (strpos($message['event'], ':ping') !== false) {
return gc_collect_cycles(); return gc_collect_cycles();
} }
$this->handleChannelSubscriptions($message, $connection); $this->handleChannelSubscriptions($message, $connection);
if (! $channel = $this->get_connection_channel($connection, $message)) { if (! $channel = $this->get_connection_channel($connection, $message)) {
return $connection->send(json_encode([ return $connection->send(json_encode([
'event' => $message['event'].':error',
'data' => [
'message' => 'Channel not found',
'meta' => $message,
],
]));
}
$this->authenticateConnection($connection, $channel, $message);
Log::channel('websocket')->info('Executing event: '.$message['event']);
if (strpos($message['event'], 'pusher') !== false) {
// try {
// return Controller::controll_message(
// $connection,
// $channel,
// $message,
// $this->channelManager
// );
// } catch (Exception $e) {
// return $connection->send(json_encode([
// 'event' => $message['event'].':error',
// 'data' => [
// 'message' => $e->getMessage(),
// ],
// ]));
// }
return $connection->send(json_encode([
'event' => $message['event'].':response',
'data' => [
'message' => 'Success',
],
]));
}
$pid = pcntl_fork();
if ($pid == -1) {
Log::error('Fork error');
} elseif ($pid == 0) {
try {
DB::reconnect();
$this->setRequest($message, $connection);
$mock = new MockConnection($connection);
Controller::controll_message(
$mock,
$channel,
$message,
$this->channelManager
);
} catch (Exception $e) {
$mock->send(json_encode([
'event' => $message['event'].':error', 'event' => $message['event'].':error',
'data' => [ 'data' => [
'message' => $e->getMessage(), 'message' => 'Channel not found',
'meta' => $message,
], ],
])); ]));
} }
exit(0); $this->authenticateConnection($connection, $channel, $message);
} else {
$this->addDataCheckLoop($connection, $message, $pid); Log::channel('websocket')->info('Executing event: '.$message['event']);
if (strpos($message['event'], 'pusher') !== false) {
return $connection->send(json_encode([
'event' => $message['event'].':response',
'data' => [
'message' => 'Success',
],
]));
}
$pid = pcntl_fork();
if ($pid == -1) {
Log::error('Fork error');
} elseif ($pid == 0) {
try {
DB::reconnect();
$this->setRequest($message, $connection);
$mock = new MockConnection($connection);
Controller::controll_message(
$mock,
$channel,
$message,
$this->channelManager
);
} catch (Exception $e) {
$mock->send(json_encode([
'event' => $message['event'].':error',
'data' => [
'message' => $e->getMessage(),
],
]));
}
exit(0);
} else {
$this->addDataCheckLoop($connection, $message, $pid);
}
} catch (\Exception $e) {
Log::channel('websocket')->error('onMessage unhandled error: '. $e->getMessage(), [
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
]);
} }
} }