Skip to content

Commit

Permalink
Merge pull request #211 from stepansnigirev/server-error-page
Browse files Browse the repository at this point in the history
Custom exception handler page
  • Loading branch information
stepansnigirev authored Jul 12, 2020
2 parents 90c1d09 + cd3f6d5 commit 5c89030
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cryptoadvance/specter/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from .user import User
from datetime import datetime
import urllib
from io import BytesIO
import traceback

from pathlib import Path
env_path = Path('.') / '.flaskenv'
Expand All @@ -32,6 +34,14 @@
from flask import current_app as app
rand = random.randint(0, 1e32) # to force style refresh

########## exception handler ##############
@app.errorhandler(Exception)
def server_error(e):
app.logger.error("Uncaught exception: %s" % e)
trace = traceback.format_exc()
return render_template('500.jinja', error=e, traceback=trace), 500

########## on every request ###############
@app.before_request
def selfcheck():
"""check status before every request"""
Expand Down
27 changes: 27 additions & 0 deletions src/cryptoadvance/specter/templates/500.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/png" href="/static/img/icon.png"/>
<title>Specter Desktop</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/static/styles.css">
<style type="text/css">
a{
color: #fff;
}
</style>
</head>
<body>
<main>
<br><br><br>
<div class="card" style="width:90%; max-width: 800px;">
<h1>Server error!</h1>
Exception: <b>{{ error }}</b><br><br>
Details:
<pre><code>{{ traceback }}</code></pre>
<br>
<div>Please let us know! Create an <a href="https://github.com/cryptoadvance/specter-desktop/issues" target="blank">issue</a> or ping us on <a href="https://t.me/spectersupport" target="blank">Telegram</a> to fix it.</div>
</div>
</main>
</body>
</html>

0 comments on commit 5c89030

Please sign in to comment.