catch 500 errors and notify discord

master
lza_menace 3 years ago
parent f178878fb5
commit 1a48e7db77

@ -4,8 +4,14 @@ from wowstash.library.jsonrpc import daemon
from wowstash.library.cache import cache from wowstash.library.cache import cache
from wowstash.library.db import Database from wowstash.library.db import Database
from wowstash.library.docker import Docker 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('/') @meta_bp.route('/')
def index(): def index():
return render_template('meta/index.html', node=daemon.info(), info=cache.get_coin_info()) return render_template('meta/index.html', node=daemon.info(), info=cache.get_coin_info())

@ -1,5 +1,8 @@
import requests
from wowstash.models import Event from wowstash.models import Event
from wowstash.factory import db from wowstash.factory import db
from wowstash import config
def capture_event(user_id, event_type): def capture_event(user_id, event_type):
@ -10,3 +13,11 @@ def capture_event(user_id, event_type):
db.session.add(event) db.session.add(event)
db.session.commit() db.session.commit()
return 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

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
{% include 'head.html' %}
<body id="page-top">
{% include 'navbar.html' %}
<header class="masthead">
<div class="container h-100">
<div class="row h-100">
<div class="col-lg-12 my-auto">
<div class="header-content-sm mx-auto">
<h2 class="mb-4">Error</h2>
<p>There was an error - an administrator has been notified.</p>
<p>Error: <code style="background-color: white;">{{ error.original_exception }}</code></p>
</div>
</div>
</div>
</div>
</header>
{% include 'footer.html' %}
{% include 'scripts.html' %}
</body>
</html>
Loading…
Cancel
Save