From 0113e4e54a498d167bf14ba843538f0d3e6d1ec3 Mon Sep 17 00:00:00 2001 From: Mitchell R Date: Tue, 26 May 2026 00:55:17 +0200 Subject: [PATCH] feat: log 5xx errors to BSB observable via h3 onError Both admin-http and api-http now log HTTP 500+ errors with status, path, and error message to BSB observable (warn level). Makes server-side errors visible in Coolify/container logs. Co-Authored-By: Claude Opus 4.6 (1M context) --- server/src/plugins/service-admin-http/index.ts | 14 +++++++++++++- server/src/plugins/service-api-http/index.ts | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/src/plugins/service-admin-http/index.ts b/server/src/plugins/service-admin-http/index.ts index 3448b9b..04a1326 100644 --- a/server/src/plugins/service-admin-http/index.ts +++ b/server/src/plugins/service-admin-http/index.ts @@ -195,7 +195,19 @@ export class Plugin extends BSBService, typeof Event otaImportApiKey: this.config.otaImportApiKey || undefined, }; - const app = new H3(); + const app = new H3({ + onError: (error, event) => { + const status = error.status ?? 500; + const path = event.req.url ?? "unknown"; + if (status >= 500) { + obs.log.warn("HTTP {status} {path}: {err}", { + status, + path, + err: error.message ?? String(error), + }); + } + }, + }); registerMiddleware(app, deps); registerStaticRoutes(app); diff --git a/server/src/plugins/service-api-http/index.ts b/server/src/plugins/service-api-http/index.ts index ed706f2..3525b6e 100644 --- a/server/src/plugins/service-api-http/index.ts +++ b/server/src/plugins/service-api-http/index.ts @@ -164,7 +164,19 @@ export class Plugin extends BSBService, typeof Event }, ); - const app = new H3(); + const app = new H3({ + onError: (error, event) => { + const status = error.status ?? 500; + const path = event.req.url ?? "unknown"; + if (status >= 500) { + obs.log.warn("HTTP {status} {path}: {err}", { + status, + path, + err: error.message ?? String(error), + }); + } + }, + }); app.get("/api/kiosk/_check", async (event) => { const token = extractBearerToken(event);