From c792f1e92fbaf0e45095b82d77e7f225798d099e Mon Sep 17 00:00:00 2001 From: fishshi <2855691008@qq.com> Date: Mon, 18 Nov 2024 03:44:55 +0800 Subject: [PATCH] fix that empty message following timeout message (#402) --- src/extension/api.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/extension/api.ts b/src/extension/api.ts index c49d230..5ba242c 100644 --- a/src/extension/api.ts +++ b/src/extension/api.ts @@ -16,14 +16,8 @@ export async function streamResponse(request: StreamRequest) { const { signal } = controller const timeOut = setTimeout(() => { - controller.abort() - onError?.(new Error("Request timed out")) - log.logConsoleError( - Logger.ErrorType.Timeout, - "Failed to establish connection", - new Error("Request timed out") - ) - }, 25000) + controller.abort(new DOMException("Request timed out", "TimeoutError")) + }, 60000) try { const url = `${options.protocol}://${options.hostname}${ @@ -102,6 +96,9 @@ export async function streamResponse(request: StreamRequest) { if (error instanceof Error) { if (error.name === "AbortError") { onEnd?.() + } else if (error.name === "TimeoutError") { + onError?.(error) + log.logConsoleError(Logger.ErrorType.Timeout, "Failed to establish connection", error) } else { log.logConsoleError(Logger.ErrorType.Fetch_Error, "Fetch error", error) onError?.(error)