about summary refs log tree commit diff stats
path: root/classes/Handler/HealthzHandler.php
diff options
context:
space:
mode:
authorfox <fox@fakecake.org>2026-10-14 21:41:11 +0300
committerGitLab <noreply@fakecake.org>2026-10-14 21:41:11 +0300
commitfa0e418228ec4ff79ef4b2024beb2491e15d538e (patch)
tree906546542b5df2689ee6a0c16b889df82f947580 /classes/Handler/HealthzHandler.php
parentc0135cc03916ad22707064e8957dce3f8e067a5d (diff)
parent48d7b08a87adec0ce1c114bd5c70c0f6e108a954 (diff)
downloadthe-epube-fa0e418228ec4ff79ef4b2024beb2491e15d538e.tar.gz
the-epube-fa0e418228ec4ff79ef4b2024beb2491e15d538e.tar.xz
Merge branch 'dev' into 'master'
Dev

See merge request git/the-epube!77
Diffstat (limited to 'classes/Handler/HealthzHandler.php')
-rw-r--r--classes/Handler/HealthzHandler.php24
1 files changed, 13 insertions, 11 deletions
diff --git a/classes/Handler/HealthzHandler.php b/classes/Handler/HealthzHandler.php
index 722422c..f12649b 100644
--- a/classes/Handler/HealthzHandler.php
+++ b/classes/Handler/HealthzHandler.php
@@ -9,38 +9,40 @@ use Request;
 use RequestHandlerInterface;
 use Response;
 
+/**
+ * Public k8s healthcheck endpoint. Intentionally does NOT implement
+ * AuthRequired. Because it is unauthenticated, it must not leak any
+ * internals (DSNs, paths, driver errors) — failure details go to the
+ * PHP error log, the HTTP response only carries 200/503.
+ */
 class HealthzHandler implements RequestHandlerInterface
 {
     public function handle(Request $request): Response
     {
-        $status = "ok";
-        $errors = [];
+        $healthy = true;
 
         // Test Calibre SQLite database
         try {
             $caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB));
             $caldb->query("SELECT 1 FROM books LIMIT 1");
         } catch (\PDOException $e) {
-            $status = "degraded";
-            $errors["calibre_db"] = "Connection failed: " . $e->getMessage();
+            $healthy = false;
+            error_log("healthz: calibre db check failed: " . $e->getMessage());
         }
 
         // Test main database (via ORM/Db)
         try {
             Db::pdo()->query("SELECT 1");
         } catch (\PDOException $e) {
-            $status = "degraded";
-            $errors["main_db"] = "Connection failed: " . $e->getMessage();
+            $healthy = false;
+            error_log("healthz: main db check failed: " . $e->getMessage());
         }
 
         $response = (new Response())
             ->withHeader("Content-Type", "application/json")
-            ->withBody(json_encode([
-                "status" => $status,
-                "errors" => $errors,
-            ]));
+            ->withBody(json_encode(["status" => $healthy ? "ok" : "error"]));
 
-        if ($status === "degraded") {
+        if (!$healthy) {
             $response = $response->withStatus(503);
         }