Error page

This commit is contained in:
Ben Arc 2021-08-23 19:19:43 +01:00
parent 0806ccfbbd
commit 449cbfed89
2 changed files with 40 additions and 12 deletions

View File

@ -6,7 +6,7 @@ import importlib
import traceback import traceback
import trio import trio
from fastapi import FastAPI from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware from fastapi.middleware.gzip import GZipMiddleware
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
@ -162,21 +162,13 @@ def register_async_tasks(app):
async def stop_listeners(): async def stop_listeners():
pass pass
templates = Jinja2Templates(directory="templates")
def register_exception_handlers(app): def register_exception_handlers(app):
@app.errorhandler(Exception) @app.errorhandler(Exception)
async def basic_error(err): async def basic_error(request: Request, err):
print("handled error", traceback.format_exc()) print("handled error", traceback.format_exc())
etype, value, tb = sys.exc_info() etype, value, tb = sys.exc_info()
traceback.print_exception(etype, err, tb) traceback.print_exception(etype, err, tb)
exc = traceback.format_exc() exc = traceback.format_exc()
return ( return await templates.TemplateResponse("templates/error.html", {"request": request, "err": err})
"\n\n".join(
[
"LNbits internal error!",
exc,
"If you believe this shouldn't be an error please bring it up on https://t.me/lnbits",
]
),
500,
)

View File

@ -0,0 +1,36 @@
{% extends "public.html" %} {% block page %}
<div class="row q-col-gutter-md justify-center">
<div class="col-12 col-md-7 col-lg-6 q-gutter-y-md">
<q-card class="q-pa-lg">
<q-card-section class="q-pa-none">
<center>
<h3 class="q-my-none">Error</h3>
<br />
<q-icon
name="warning"
class="text-grey"
style="font-size: 20rem"
></q-icon>
<h5 class="q-my-none">{{ err }}</h5>
<h4>If you believe this shouldn't be an error please bring it up on https://t.me/lnbits</h4>
<br />
</center>
</q-card-section>
</q-card>
</div>
{% endblock %} {% block scripts %}
<script>
new Vue({
el: '#vue',
mixins: [windowMixin],
data: function () {
return {}
}
})
</script>
{% endblock %}
</div>