add exception to realtime opener
This commit is contained in:
parent
1017a2fb6b
commit
d41a8ef44b
|
@ -142,13 +142,12 @@ $server->on('open', function (Server $server, Request $request) use (&$connectio
|
|||
/** @var Appwrite\Database\Document $console */
|
||||
$console = $app->getResource('console');
|
||||
|
||||
try {
|
||||
/*
|
||||
* Project Check
|
||||
*/
|
||||
if (empty($project->getId())) {
|
||||
$server->push($connection, 'Missing or unknown project ID');
|
||||
$server->close($connection);
|
||||
return;
|
||||
throw new Exception('Missing or unknown project ID', 1008);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -165,9 +164,7 @@ $server->on('open', function (Server $server, Request $request) use (&$connectio
|
|||
$abuse = new Abuse($timeLimit);
|
||||
|
||||
if ($abuse->check() && App::getEnv('_APP_OPTIONS_ABUSE', 'enabled') === 'enabled') {
|
||||
$server->push($connection, 'Too many requests');
|
||||
$server->close($connection);
|
||||
return;
|
||||
throw new Exception('Too many requests', 1013);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -179,9 +176,7 @@ $server->on('open', function (Server $server, Request $request) use (&$connectio
|
|||
$originValidator = new Origin(\array_merge($project->getAttribute('platforms', []), $console->getAttribute('platforms', [])));
|
||||
|
||||
if (!$originValidator->isValid($origin)) {
|
||||
$server->push($connection, $originValidator->getDescription());
|
||||
$server->close($connection);
|
||||
return;
|
||||
throw new Exception($originValidator->getDescription(), 1008);
|
||||
}
|
||||
|
||||
Realtime::setUser($user);
|
||||
|
@ -193,14 +188,20 @@ $server->on('open', function (Server $server, Request $request) use (&$connectio
|
|||
* Channels Check
|
||||
*/
|
||||
if (empty($channels)) {
|
||||
$server->push($connection, 'Missing channels');
|
||||
$server->close($connection);
|
||||
return;
|
||||
throw new Exception('Missing channels', 1008);
|
||||
}
|
||||
|
||||
Realtime::subscribe($project->getId(), $connection, $roles, $subscriptions, $connections, $channels);
|
||||
|
||||
$server->push($connection, json_encode($channels));
|
||||
} catch (\Throwable $th) {
|
||||
$response = [
|
||||
'code' => $th->getCode(),
|
||||
'message' => $th->getMessage()
|
||||
];
|
||||
$server->push($connection, json_encode($response));
|
||||
$server->close($connection);
|
||||
}
|
||||
});
|
||||
|
||||
$server->on('message', function (Server $server, Frame $frame) {
|
||||
|
|
Loading…
Reference in a new issue