From 2d814b1e433ae96b36579b2fa882e9a17652e7a5 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 26 Dec 2023 10:00:49 +0100 Subject: [PhpServer] correct exception handling --- src/Server/RequestHandlers/PhpServer.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/Server/RequestHandlers/PhpServer.php') diff --git a/src/Server/RequestHandlers/PhpServer.php b/src/Server/RequestHandlers/PhpServer.php index 5447f72..c3ded4d 100644 --- a/src/Server/RequestHandlers/PhpServer.php +++ b/src/Server/RequestHandlers/PhpServer.php @@ -19,23 +19,19 @@ class PhpServer extends DocumentServer } if (is_file($documentPath) && str_ends_with($documentPath, '.php')) { - ob_start(); try { + ob_start(); include $documentPath; - } catch (\Throwable $exception) { - echo <<setStatusCode(Status::SUCCESS); + $response->setBody($content); + $response->setMeta('text/gemini; charset=utf-8'); + } catch (\Throwable $exception) { + $response->setStatusCode(Status::PERMANENT_FAILURE); + $response->setMeta($exception); } - $content = ob_get_clean(); - $response->setBody($content); - $response->setStatusCode(Status::SUCCESS); - $response->setMeta('text/gemini; charset=utf-8'); } else { return parent::__invoke($response, $request); } -- cgit v1.2.3