Skip to content

Commit 1ba06ac

Browse files
gorkemozkanShivangi-Lokal-26
authored andcommitted
fix: enhance URL handling in NetworkInterceptor for better request input processing
- Improved URL extraction logic to prioritize Request/URL fields - Added fallback mechanisms for various input types to ensure robust handling
1 parent b699b56 commit 1ba06ac

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/interceptors/NetworkInterceptor.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,18 @@ export class NetworkInterceptor {
200200
): typeof global.fetch {
201201
return async (input: RequestInfo | URL, init?: RequestInit) => {
202202
const startTime = performance.now();
203-
const url = typeof input === 'string' ? input : input.toString();
203+
const url =
204+
typeof input === 'string'
205+
? input
206+
: typeof input === 'object' && input !== null
207+
? // Prefer Request/URL fields when available; fall back to string conversion.
208+
(input as Request).url ||
209+
(input as URL).href ||
210+
(typeof (input as { toString?: () => string }).toString ===
211+
'function'
212+
? (input as { toString: () => string }).toString()
213+
: String(input))
214+
: String(input);
204215
const method = (init?.method || 'GET').toUpperCase();
205216

206217
try {

0 commit comments

Comments
 (0)