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:
co-authored by
Claude Opus 5.5
parent
a14c4e7747
commit
06a59e1b5c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user