koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.36k stars 236 forks source link

Bug: Status code 400 (It seems that the token expired) for feishu adapter #1009

Closed TimeBather closed 1 year ago

TimeBather commented 1 year ago

Describe the bug

When the bot was sending the message to the server, the koishi throw an error:

2023-03-06 16:29:27 [W] session AxiosError: Request failed with status code 400

It appear after my bot started for about half day. It seems that this error is caused by the token expiration.

Steps to reproduce

Expected behavior

Screenshots

2023-03-06 16:29:27 [W] session AxiosError: Request failed with status code 400
                            at settle (/usr/koishi/sumka-server/node_modules/axios/dist/node/axios.cjs:1268:12)
                            at IncomingMessage.handleStreamEnd (/usr/koishi/sumka-server/node_modules/axios/dist/node/axios.cjs:2446:11)
                            at IncomingMessage.emit (node:events:525:35)
                            at endReadableNT (node:internal/streams/readable:1359:12)
                            at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

No feishu api server log detected. Here is the feishu requester log:

{
  "eventId": "64*******************eb",
  "success": "success",
  "appId": "cli_************",
  "tenantKey": "2***********f",
  "eventType": "im.message.receive_v1",
  "hookType": 1,
  "address": "http://************/adapters/feishu",
  "retryCnt": "-",
  "costMills": 121,
  "errorInfo": "",
  "httpCode": 200,
  "eventTime": "1***********2"
}

Versions

Additional context

None

shigma commented 1 year ago

duplicate of #1008?

TimeBather commented 1 year ago

No , #1008 is a bug with image sending problem, not the authentication problem.

I am sure that it has enough permission for my bot because I use the same command to test it after I restarting the bot and waiting for half day. But it can send messages in the first condition but throw a 400 error in the last one.

TimeBather commented 1 year ago

https://github.com/satorijs/satori/blob/c073802609a60579e43bb8d06a73fae0ee1b7e5c/adapters/feishu/src/bot.ts#LL43C4-L43C4 I searched the references of refershToken() method in the satori project , and this method was only called by the initialize method. And another thing I found that the refreshToken method did not read the expiration of the token . Is it the cause of this problem?

MaikoTan commented 1 year ago

You're right. This is a point that could be optimised. Axios allows you to add a pre request hook, so I think the token refreshing could be put here.

MaikoTan commented 1 year ago

Resolved in https://github.com/satorijs/satori/pull/81