From e84480fdbf7e9a212b1f95e1c7bbbd89bac8dd3a Mon Sep 17 00:00:00 2001 From: Zuhwa Date: Tue, 24 Feb 2026 17:46:01 +0800 Subject: [PATCH] Retry token refresh --- src/acpClient.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/acpClient.ts b/src/acpClient.ts index d7074d4..d2af3cb 100644 --- a/src/acpClient.ts +++ b/src/acpClient.ts @@ -113,6 +113,24 @@ class AcpClient { return config; }); + this.acpClient.interceptors.response.use( + (response) => response, + async (error) => { + const originalRequest = error.config; + if ( + error.response?.status === 401 && + originalRequest && + !originalRequest._retried + ) { + originalRequest._retried = true; + this.accessToken = null; + + return this.acpClient(originalRequest); + } + return Promise.reject(error); + } + ); + this.onNewTask = options.onNewTask; this.onEvaluate = options.onEvaluate || this.defaultOnEvaluate;