-
Sometimes, I can't edit a message by its callback query, API response description shows "Bad Request: message to edit not found" or "Bad Request: MESSAGE_ID_INVALID" (I guess telegram save message id in cache for a short time), so I need to check if error.Description = "Bad Request: message to edit not found" or "Bad Request: MESSAGE_ID_INVALID" now my code, use strings.Contains _, err := bot.EditMessageText(
&telego.EditMessageTextParams{
Text: text,
MessageID: query.Message.GetMessageID(),
ChatID: telego.ChatID{ID: query.Message.GetChat().ID},
ParseMode: telego.ModeHTML,
},
)
if err != nil {
if strings.Contains(err.Error(), "Bad Request: message to edit not found") || strings.Contains(err.Error(), "Bad Request: MESSAGE_ID_INVALID") {
bot.AnswerCallbackQuery(
&telego.AnswerCallbackQueryParams{
CallbackQueryID: query.ID,
ShowAlert: true,
Text: "message expired,please resend request",
},
)
} but I wonder if is there any way I can access original error directly ? And another way, is it possible to define some error type in advance according to the response description? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, you can get original error message, Telego has type for that, please see example: _, err := bot.EditMessageText(...)
if err != nil {
var apiErr *ta.Error
if errors.As(err, &apiErr) {
fmt.Println(apiErr.Description, apiErr.ErrorCode)
}
return err
}
|
Beta Was this translation helpful? Give feedback.
Yes, you can get original error message, Telego has type for that, please see example: