about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-10-14 21:24:02 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-10-14 21:24:02 +0300
commit0cf1c3a4611d1c752fefec64a75893a00a533be8 (patch)
tree17df5485a0748b5d54fcd4a97c9bc69325c19329
parentaf1855a81a1dc3f0838110bf4c4e394a05a36373 (diff)
downloadthe-epube-0cf1c3a4611d1c752fefec64a75893a00a533be8.tar.gz
the-epube-0cf1c3a4611d1c752fefec64a75893a00a533be8.tar.xz
stop returning detailed info in /healthz
-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);
         }