Skip to content

Commit 8fe6259

Browse files
juliusmarmingecodex
andcommitted
Reuse shared URL diagnostics
Co-authored-by: codex <[email protected]>
1 parent 4439955 commit 8fe6259

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

‎apps/web/src/components/preview/reportPreviewActionFailure.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics";
2+
13
export interface PreviewActionFailureContext {
24
readonly operation: string;
35
readonly threadKey?: string;
@@ -11,19 +13,11 @@ export interface PreviewActionFailureContext {
1113
}
1214

1315
export function previewUrlFailureContext(url: string) {
14-
let urlHostname: string | undefined;
15-
let urlProtocol: string | undefined;
16-
try {
17-
const parsed = new URL(url);
18-
urlHostname = parsed.hostname || undefined;
19-
urlProtocol = parsed.protocol || undefined;
20-
} catch {
21-
// Invalid targets still retain a nonsecret input length for diagnostics.
22-
}
16+
const diagnostics = getUrlDiagnostics(url);
2317
return {
24-
urlLength: url.length,
25-
...(urlHostname === undefined ? {} : { urlHostname }),
26-
...(urlProtocol === undefined ? {} : { urlProtocol }),
18+
urlLength: diagnostics.inputLength,
19+
...(diagnostics.hostname === undefined ? {} : { urlHostname: diagnostics.hostname }),
20+
...(diagnostics.protocol === undefined ? {} : { urlProtocol: diagnostics.protocol }),
2721
};
2822
}
2923

0 commit comments

Comments
 (0)