Skip to content

Commit 9222569

Browse files
committed
fix: apply same nullish detail guard to throwRawApiError (Bugbot)
The nullish detail fix from the previous commit only covered throwApiError (SDK path). throwRawApiError (raw fetch path via apiRequestToRegion) had the same issue: { detail: null } would produce {"detail":null} as visible output in 403 enrichment. Now checks typeof parsed.detail before using it, and skips the JSON.stringify fallback for 403 errors.
1 parent caa952b commit 9222569

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/lib/api/infrastructure.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,17 @@ async function throwRawApiError(
416416
const text = await response.text();
417417
try {
418418
const parsed = JSON.parse(text) as { detail?: string };
419-
detail = parsed.detail ?? JSON.stringify(parsed);
419+
// Prefer the explicit `detail` field; fall back to the full JSON
420+
// for non-403 errors (useful for debugging). For 403s, pass
421+
// undefined so enrich403Detail stands alone without a noisy
422+
// `{"detail":null}` prefix.
423+
if (typeof parsed.detail === "string") {
424+
detail = parsed.detail;
425+
} else if (response.status !== 403) {
426+
detail = JSON.stringify(parsed);
427+
}
420428
} catch {
421-
detail = text;
429+
detail = text || undefined;
422430
}
423431
} catch {
424432
detail = response.statusText;

0 commit comments

Comments
 (0)