From 6b509917657c47f3574288dcd799566d1c57837a Mon Sep 17 00:00:00 2001 From: _LittleC_ <26459759+XxLittleCxX@users.noreply.github.com> Date: Mon, 19 Feb 2024 04:08:37 +0800 Subject: [PATCH] fix(qq): trace id logging (#237) --- adapters/qq/src/bot/index.ts | 4 ++-- adapters/qq/src/internal/internal.ts | 6 +++--- adapters/qq/src/message.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/adapters/qq/src/bot/index.ts b/adapters/qq/src/bot/index.ts index 844ad6a1..44e0e8a2 100644 --- a/adapters/qq/src/bot/index.ts +++ b/adapters/qq/src/bot/index.ts @@ -70,7 +70,7 @@ export class QQBot extends Bot { }, }) if (!result.data.access_token) { - this.logger.warn(`POST https://bots.qq.com/app/getAppAccessToken response: %o, trace id: %s`, result.data, result.headers['x-tps-trace-id']) + this.logger.warn(`POST https://bots.qq.com/app/getAppAccessToken response: %o, trace id: %s`, result.data, result.headers.get('x-tps-trace-id')) throw new Error('failed to refresh access token') } let endpoint = this.config.endpoint @@ -92,7 +92,7 @@ export class QQBot extends Bot { }, (result.data.expires_in - 40) * 1000) } catch (e) { if (!Quester.isAxiosError(e) || !e.response) throw e - this.logger.warn(`POST https://bots.qq.com/app/getAppAccessToken response: %o, trace id: %s`, e.response.data, e.response.headers['x-tps-trace-id']) + this.logger.warn(`POST https://bots.qq.com/app/getAppAccessToken response: %o, trace id: %s`, e.response.data, e.response.headers.get('x-tps-trace-id')) throw e } } diff --git a/adapters/qq/src/internal/internal.ts b/adapters/qq/src/internal/internal.ts index 7fca44e0..1734d31f 100644 --- a/adapters/qq/src/internal/internal.ts +++ b/adapters/qq/src/internal/internal.ts @@ -30,12 +30,12 @@ export class Internal { try { this.bot.logger.debug(`${method} ${url} request: %o`, config) const response = await this.http()(url, { ...config, method }) - this.bot.logger.debug(`${method} ${url} response: %o, trace id: %s`, response.data, response.headers['x-tps-trace-id']) + this.bot.logger.debug(`${method} ${url} response: %o, trace id: %s`, response.data, response.headers.get('x-tps-trace-id')) return response.data } catch (error) { this.bot.logger.warn(`${method} ${url} request: %o`, config) - if (!Quester.isAxiosError(error) || !error.response) throw error - this.bot.logger.warn(`${method} ${url} response: %o, trace id: %s`, error.response.data, error.response.headers['x-tps-trace-id']) + if (!Quester.Error.is(error) || !error.response) throw error + this.bot.logger.warn(`${method} ${url} response: %o, trace id: %s`, error.response.data, error.response.headers.get('x-tps-trace-id')) throw error } } diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index 54f3721e..d5de2b61 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -80,7 +80,7 @@ export class QQGuildMessageEncoder extends MessageE await this.flush() } if (useFormData) { - this.bot.logger.warn(`POST ${endpoint} response: %o, trace id: %s`, e.response.data, e.response.headers['x-tps-trace-id']) + this.bot.logger.warn(`POST ${endpoint} response: %o, trace id: %s`, e.response.data, e.response.headers.get('x-tps-trace-id')) } } }