Skip to content

Commit

Permalink
Merge pull request #5 from randhana/4-improve-error-handling-in-teleg…
Browse files Browse the repository at this point in the history
…rambot-_handle_response-method

Improve error handling in _handle_response method
  • Loading branch information
randhana authored Jun 26, 2024
2 parents 1cbf6f9 + 6cff723 commit 0f0a667
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions telebotpy/telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ def _get_date_time(self):
return f"Date: {date} {time}"

def _handle_response(self, response):
if response.status_code == 200:
try:
response.raise_for_status()
print("Request successful.")
else:
except requests.exceptions.HTTPError as e:
print(f"Request failed. Error code: {response.status_code}")
print(response.text)
except requests.exceptions.RequestException as e:
print(f"Request exception: {e}")

def send_text_message(self, message):
url = f"https://api.telegram.org/bot{self.token}/sendMessage"
Expand Down

0 comments on commit 0f0a667

Please sign in to comment.