Skip to content

Commit

Permalink
Added rescue to prevent failure due to error in headers, instead, jus…
Browse files Browse the repository at this point in the history
…t report.
  • Loading branch information
lotharthesavior committed Dec 22, 2023
1 parent 2c6fe70 commit 698b306
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Services/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public function run(): void

if (false === config('jacked-server.websocket.enabled', true)) {
// TODO: craft HTTP only server
throw new Exception('WebSockets are not enabled! HTTP only servers are not available yet by Jacked Server.');
throw new Exception(
'WebSockets are not enabled! HTTP only servers are not ' .
'available yet by Jacked Server.',
);
}

$this->wsPersistence = Conveyor::defaultPersistence();
Expand All @@ -122,7 +125,8 @@ public function run(): void
ssl: $ssl ? Constant::SOCK_TCP | Constant::SSL : Constant::SOCK_TCP,
serverOptions: $this->getServerConfig($ssl),
eventListeners: [
ConveyorServer::EVENT_SERVER_STARTED => fn(ServerStartedEvent $event) => $this->handleStart($event->server),
ConveyorServer::EVENT_SERVER_STARTED => fn(ServerStartedEvent $event) =>
$this->handleStart($event->server),
ConveyorServer::EVENT_PRE_SERVER_START => function (PreServerStartEvent $event) use ($ssl) {
if ($ssl) {
$event->server->listen(
Expand Down Expand Up @@ -189,7 +193,7 @@ public function handleWsHandshake(Request $request, Response $response): bool
return false;
}

foreach($headers as $headerKey => $val) {
foreach ($headers as $headerKey => $val) {
$response->header($headerKey, $val);
}

Expand Down Expand Up @@ -277,7 +281,16 @@ private function sendResponse(Response $response, JackedResponse $jackedResponse

// header
foreach ($headers as $headerKey => $headerValue) {
$response->header($headerKey, $headerValue);
rescue(
fn() => $response->header($headerKey, $headerValue),
function () use ($status, $headers) {
$this->logger->error('Server Error', [
'headers' => $headers,
'status' => $status,
]);
},
false,
);
}

// status
Expand Down

0 comments on commit 698b306

Please sign in to comment.