Skip to content

Commit

Permalink
fix(qq): trace id logging (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX authored Feb 18, 2024
1 parent 4dbb629 commit 6b50991
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions adapters/qq/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class QQBot<C extends Context = Context> extends Bot<C, QQBot.Config> {
},
})
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
Expand All @@ -92,7 +92,7 @@ export class QQBot<C extends Context = Context> extends Bot<C, QQBot.Config> {
}, (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
}
}
Expand Down
6 changes: 3 additions & 3 deletions adapters/qq/src/internal/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/qq/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class QQGuildMessageEncoder<C extends Context = Context> 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'))
}
}
}
Expand Down

0 comments on commit 6b50991

Please sign in to comment.