diff --git a/wowstash/blueprints/meta/routes.py b/wowstash/blueprints/meta/routes.py index 1502618..530caec 100644 --- a/wowstash/blueprints/meta/routes.py +++ b/wowstash/blueprints/meta/routes.py @@ -4,8 +4,14 @@ from wowstash.library.jsonrpc import daemon from wowstash.library.cache import cache from wowstash.library.db import Database from wowstash.library.docker import Docker +from wowstash.library.helpers import post_discord_webhook +@meta_bp.errorhandler(500) +def internal_error(error): + post_discord_webhook(f'500 error: {error.original_exception}') + return render_template('meta/500.html', error=error) + @meta_bp.route('/') def index(): return render_template('meta/index.html', node=daemon.info(), info=cache.get_coin_info()) diff --git a/wowstash/library/helpers.py b/wowstash/library/helpers.py index 8dc2e42..217c52a 100644 --- a/wowstash/library/helpers.py +++ b/wowstash/library/helpers.py @@ -1,5 +1,8 @@ +import requests + from wowstash.models import Event from wowstash.factory import db +from wowstash import config def capture_event(user_id, event_type): @@ -10,3 +13,11 @@ def capture_event(user_id, event_type): db.session.add(event) db.session.commit() return + +def post_discord_webhook(text): + try: + r = requests.post(config.DISCORD_URL, data={"content": text}) + r.raise_for_status() + return True + except: + return False diff --git a/wowstash/templates/meta/500.html b/wowstash/templates/meta/500.html new file mode 100644 index 0000000..31323ce --- /dev/null +++ b/wowstash/templates/meta/500.html @@ -0,0 +1,30 @@ + + + + {% include 'head.html' %} + + + + {% include 'navbar.html' %} + +
+
+
+
+
+

Error

+

There was an error - an administrator has been notified.

+

Error: {{ error.original_exception }}

+
+
+
+
+
+ + {% include 'footer.html' %} + + {% include 'scripts.html' %} + + + +