fix(sdk): block real network in test context, strip query from HttpError message

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-30 15:38:45 +01:00
co-authored by Claude Opus 5.5
parent a14c4e7747
commit 06a59e1b5c
3 changed files with 32 additions and 2 deletions
+11 -1
View File
@@ -1,10 +1,20 @@
import type { HttpClient } from "./types.ts";
/** Origin + pathname only: query strings may carry API keys or tokens. */
function safeUrl(url: string): string {
try {
const u = new URL(url);
return u.origin + u.pathname;
} catch {
return url.split(/[?#]/)[0] ?? "";
}
}
export class HttpError extends Error {
readonly status: number;
readonly body: string;
constructor(status: number, body: string, url = "") {
super(`HTTP ${status}${url ? ` for ${url}` : ""}`);
super(`HTTP ${status}${url ? ` for ${safeUrl(url)}` : ""}`);
this.name = "HttpError";
this.status = status;
this.body = body;