fix: Refactor service port handling in DevChatClient
- Remove redundant baseURL checks in _get, _post, and chat methods - Simplify port initialization logic for HTTP requests - Consolidate error handling for missing service port configuration
This commit is contained in:
parent
341380c8c4
commit
ff717fe55d
@ -150,7 +150,6 @@ export class DevChatClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _get(path: string, config?: any): Promise<AxiosResponse> {
|
async _get(path: string, config?: any): Promise<AxiosResponse> {
|
||||||
if (!this.baseURL) {
|
|
||||||
if (!process.env.DC_LOCALSERVICE_PORT) {
|
if (!process.env.DC_LOCALSERVICE_PORT) {
|
||||||
logger.channel()?.info("No local service port found.");
|
logger.channel()?.info("No local service port found.");
|
||||||
throw new DCLocalServicePortNotSetError();
|
throw new DCLocalServicePortNotSetError();
|
||||||
@ -158,7 +157,6 @@ export class DevChatClient {
|
|||||||
logger.channel()?.trace("Using local service port:", process.env.DC_LOCALSERVICE_PORT);
|
logger.channel()?.trace("Using local service port:", process.env.DC_LOCALSERVICE_PORT);
|
||||||
const port: number = parseInt(process.env.DC_LOCALSERVICE_PORT || '8008', 10);
|
const port: number = parseInt(process.env.DC_LOCALSERVICE_PORT || '8008', 10);
|
||||||
this.baseURL = `http://localhost:${port}`;
|
this.baseURL = `http://localhost:${port}`;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.channel()?.debug(`GET request to ${this.baseURL}${path}`);
|
logger.channel()?.debug(`GET request to ${this.baseURL}${path}`);
|
||||||
@ -170,7 +168,6 @@ export class DevChatClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async _post(path: string, data: any = undefined): Promise<AxiosResponse> {
|
async _post(path: string, data: any = undefined): Promise<AxiosResponse> {
|
||||||
if (!this.baseURL) {
|
|
||||||
if (!process.env.DC_LOCALSERVICE_PORT) {
|
if (!process.env.DC_LOCALSERVICE_PORT) {
|
||||||
logger.channel()?.info("No local service port found.");
|
logger.channel()?.info("No local service port found.");
|
||||||
throw new DCLocalServicePortNotSetError();
|
throw new DCLocalServicePortNotSetError();
|
||||||
@ -178,7 +175,6 @@ export class DevChatClient {
|
|||||||
logger.channel()?.trace("Using local service port:", process.env.DC_LOCALSERVICE_PORT);
|
logger.channel()?.trace("Using local service port:", process.env.DC_LOCALSERVICE_PORT);
|
||||||
const port: number = parseInt(process.env.DC_LOCALSERVICE_PORT || '8008', 10);
|
const port: number = parseInt(process.env.DC_LOCALSERVICE_PORT || '8008', 10);
|
||||||
this.baseURL = `http://localhost:${port}`;
|
this.baseURL = `http://localhost:${port}`;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.channel()?.debug(`POST request to ${this.baseURL}${path}`);
|
logger.channel()?.debug(`POST request to ${this.baseURL}${path}`);
|
||||||
@ -249,14 +245,12 @@ export class DevChatClient {
|
|||||||
message: ChatRequest,
|
message: ChatRequest,
|
||||||
onData: (data: ChatResponse) => void
|
onData: (data: ChatResponse) => void
|
||||||
): Promise<ChatResponse> {
|
): Promise<ChatResponse> {
|
||||||
if (!this.baseURL) {
|
|
||||||
if (!process.env.DC_LOCALSERVICE_PORT) {
|
if (!process.env.DC_LOCALSERVICE_PORT) {
|
||||||
logger.channel()?.info("No local service port found.");
|
logger.channel()?.info("No local service port found.");
|
||||||
}
|
}
|
||||||
logger.channel()?.trace("Using local service port:", process.env.DC_LOCALSERVICE_PORT);
|
logger.channel()?.trace("Using local service port:", process.env.DC_LOCALSERVICE_PORT);
|
||||||
const port: number = parseInt(process.env.DC_LOCALSERVICE_PORT || '8008', 10);
|
const port: number = parseInt(process.env.DC_LOCALSERVICE_PORT || '8008', 10);
|
||||||
this.baseURL = `http://localhost:${port}`;
|
this.baseURL = `http://localhost:${port}`;
|
||||||
}
|
|
||||||
|
|
||||||
this._cancelMessageToken = axios.CancelToken.source();
|
this._cancelMessageToken = axios.CancelToken.source();
|
||||||
const workspace = UiUtilWrapper.workspaceFoldersFirstPath();
|
const workspace = UiUtilWrapper.workspaceFoldersFirstPath();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user