Skip to content

Instantly share code, notes, and snippets.

Last active April 23, 2023 17:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import requests
def send_error_to_teams(error_message, webhook_url):
""" This function will use the requests library to make a POST request to the webhook URL with the error message as the payload """
payload = {
"text": error_message
response =, json=payload)
def send_error_to_teams_decorator(webhook_url):
""" This function takes a function as its argument and returns a new function that wraps the original function.
Inside the wrapper function, you can catch any errors that occur and send them to the Teams channel using the send_error_to_teams function """
def decorator(original_function):
def wrapper(*args, **kwargs):
result = original_function(*args, **kwargs)
return result
except Exception as e:
error_message = f"Error in {original_function.__name__}: {str(e)}"
send_error_to_teams(error_message, webhook_url)
print(f"Error send to teams channel: {error_message}")
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment