removed http client for a simple fetch wrapper with logging in utils

This commit is contained in:
Boki 2025-06-22 09:03:34 -04:00
parent 89cbfb7848
commit a07a71d92a
36 changed files with 100 additions and 1465 deletions

27
libs/utils/src/fetch.ts Normal file
View file

@ -0,0 +1,27 @@
/**
* Minimal fetch wrapper with automatic debug logging
* Drop-in replacement for native fetch with logging support
*/
export function fetch(
input: RequestInfo | URL,
init?: RequestInit & { logger?: any }
): Promise<Response> {
const logger = init?.logger || console;
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
const method = init?.method || 'GET';
logger.debug('HTTP request', { method, url });
return globalThis.fetch(input, init).then(response => {
logger.debug('HTTP response', {
url,
status: response.status,
ok: response.ok
});
return response;
}).catch(error => {
logger.debug('HTTP error', { url, error: error.message });
throw error;
});
}