fix: onError uses init obs when request trace missing

If event.context.obs not set, fall back to init-level obs and
flag no request trace in error message.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mitchell R 2026-05-26 01:34:14 +02:00
parent 925d9fd6dc
commit 85f8456cf0
No known key found for this signature in database
2 changed files with 18 additions and 2 deletions

View file

@ -208,9 +208,17 @@ export class Plugin extends BSBService<InstanceType<typeof Config>, typeof Event
event.context.obs = reqObs;
},
onError: (error, event) => {
const reqObs = event.context.obs ?? obs;
const reqObs = event.context.obs;
const status = error.status ?? 500;
const path = event.req.url ?? "unknown";
if (!reqObs) {
obs.log.error("HTTP {status} {path}: {err} (no request trace)", {
status,
path,
err: error.message ?? String(error),
});
return;
}
if (status >= 500) {
reqObs.log.error("HTTP {status} {path}: {err}", {
status,

View file

@ -177,9 +177,17 @@ export class Plugin extends BSBService<InstanceType<typeof Config>, typeof Event
event.context.obs = reqObs;
},
onError: (error, event) => {
const reqObs = event.context.obs ?? obs;
const reqObs = event.context.obs;
const status = error.status ?? 500;
const path = event.req.url ?? "unknown";
if (!reqObs) {
obs.log.error("HTTP {status} {path}: {err} (no request trace)", {
status,
path,
err: error.message ?? String(error),
});
return;
}
if (status >= 500) {
reqObs.log.error("HTTP {status} {path}: {err}", {
status,