working on proxy service. getting closer
This commit is contained in:
parent
6380165a94
commit
afc1843fdb
5 changed files with 91 additions and 892 deletions
|
|
@ -7,7 +7,7 @@ import type {
|
|||
import { HttpError } from './types.js';
|
||||
import { ProxyManager } from './proxy-manager.js';
|
||||
import axios, { type AxiosResponse, AxiosError } from 'axios';
|
||||
import { clear } from 'node:console';
|
||||
import { loggingConfig } from '@stock-bot/config';
|
||||
|
||||
export class HttpClient {
|
||||
private readonly config: HttpClientConfig;
|
||||
|
|
@ -15,8 +15,9 @@ export class HttpClient {
|
|||
|
||||
constructor(config: HttpClientConfig = {}, logger?: Logger) {
|
||||
this.config = config;
|
||||
this.logger = logger?.child({
|
||||
this.logger = logger?.child({ //TODO fix pino levels
|
||||
component: 'http',
|
||||
// level: loggingConfig?.LOG_LEVEL || 'info',
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -68,11 +69,11 @@ export class HttpClient {
|
|||
|
||||
return response;
|
||||
} catch (error) {
|
||||
this.logger?.warn('HTTP request failed', {
|
||||
method: finalConfig.method,
|
||||
url: finalConfig.url,
|
||||
error: (error as Error).message,
|
||||
});
|
||||
// this.logger?.warn('HTTP request failed', {
|
||||
// method: finalConfig.method,
|
||||
// url: finalConfig.url,
|
||||
// error: (error as Error).message,
|
||||
// });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -124,10 +125,10 @@ export class HttpClient {
|
|||
try {
|
||||
const options = this.buildFetchOptions(config, signal);
|
||||
|
||||
this.logger?.debug('Making request with fetch: ', { url: config.url, options })
|
||||
|
||||
this.logger?.debug('Making request with fetch: ', { url: config.url, options })
|
||||
// console.log(options)
|
||||
const response = await fetch(config.url, options);
|
||||
|
||||
// console.log('Fetch response:', response.status);
|
||||
return this.parseFetchResponse<T>(response);
|
||||
} catch (error) {
|
||||
throw signal.aborted
|
||||
|
|
@ -201,7 +202,6 @@ export class HttpClient {
|
|||
if (config.proxy && ProxyManager.shouldUseBunFetch(config.proxy)) {
|
||||
(options as any).proxy = ProxyManager.createProxyUrl(config.proxy);
|
||||
}
|
||||
|
||||
return options;
|
||||
} /**
|
||||
* Build Axios options (for reference, though we're creating instance in ProxyManager)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue