Skip to content

Log error message received from telegram instead of generic#58

Merged
smartnode merged 1 commit intosmartnode:masterfrom
Nachtalb:feature/meaningful-http-error-log
Oct 14, 2023
Merged

Log error message received from telegram instead of generic#58
smartnode merged 1 commit intosmartnode:masterfrom
Nachtalb:feature/meaningful-http-error-log

Conversation

@Nachtalb
Copy link
Contributor

Telegram returns helpful error messages. Show these to the developer so that he knows what the problem is.

Here is an example:

void echo_photo_as_document(telebot_handler_t handle, telebot_update_t update) {
  telebot_error_e   ret;
  telebot_message_t message = update.message;

  telebot_photo_t photo = message.photos[message.count_photos - 1];

  char *caption;
  asprintf(&caption, "width: %d, height: %d, file_size: %d", photo.width,
           photo.height, photo.file_size);

  ret = telebot_send_document(handle, message.chat->id, photo.file_id, false, NULL,
                              caption, "HTML", false, 0, "");

  free(caption);

  if (ret != TELEBOT_ERROR_NONE) {
    printf("Failed to send message: %d \n", ret);
  }
}

This would now return:

[ERROR][telebot_core_curl_perform:145]HTTP error: 400 - "Bad Request: can't use file of type Photo as Document"

@smartnode smartnode merged commit c74d78d into smartnode:master Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants