From 171354e79f99976547e29a5fbdb9a8d06d88407a Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Sat, 23 Nov 2024 00:56:34 +0800 Subject: [PATCH] fix(agent): fix health chck request canceled error handler. (#3457) * fix(agent): fix health chck request canceled error handler. * fix(agent): fix health chck request canceled error handler. --- .../tabby-agent/src/http/tabbyApiClient.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 9ca8f044d4a4..35121927101a 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -273,29 +273,30 @@ export class TabbyApiClient extends EventEmitter { this.serverHealth = response.data; this.updateStatus("ready"); } catch (error) { - this.serverHealth = undefined; - if (error instanceof HttpError && error.status == 405 && method !== "POST") { + if (isCanceledError(error)) { + this.logger.debug(`Health check request canceled. [${requestId}]`); + } else if (error instanceof HttpError && error.status == 405 && method !== "POST") { return await this.healthCheck(signal, "POST"); } else if (isUnauthorizedError(error)) { + this.serverHealth = undefined; this.updateStatus("unauthorized"); + } else if (isTimeoutError(error)) { + this.logger.error(`Health check request timed out. [${requestId}]`, error); + this.serverHealth = undefined; + this.connectionErrorMessage = `${requestDescription} timed out.`; + this.updateStatus("noConnection"); } else { - if (isCanceledError(error)) { - this.logger.debug(`Health check request canceled. [${requestId}]`); - this.connectionErrorMessage = `${requestDescription} canceled.`; - } else if (isTimeoutError(error)) { - this.logger.error(`Health check request timed out. [${requestId}]`, error); - this.connectionErrorMessage = `${requestDescription} timed out.`; - } else { - this.logger.error(`Health check request failed. [${requestId}]`, error); - const message = error instanceof Error ? errorToString(error) : JSON.stringify(error); - this.connectionErrorMessage = `${requestDescription} failed: \n${message}`; - } + this.logger.error(`Health check request failed. [${requestId}]`, error); + this.serverHealth = undefined; + const message = error instanceof Error ? errorToString(error) : JSON.stringify(error); + this.connectionErrorMessage = `${requestDescription} failed: \n${message}`; this.updateStatus("noConnection"); } - } - if (this.healthCheckMutexAbortController === abortController) { - this.healthCheckMutexAbortController = undefined; - this.updateIsConnecting(false); + } finally { + if (this.healthCheckMutexAbortController === abortController) { + this.healthCheckMutexAbortController = undefined; + this.updateIsConnecting(false); + } } }