1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Custom HTTP error pages

This commit is contained in:
Krateng 2019-04-03 18:03:55 +02:00
parent 4557a208e9
commit 15d4a588d8
3 changed files with 57 additions and 3 deletions

View File

@ -39,6 +39,33 @@ def mainpage():
response = static_html("start") response = static_html("start")
return response return response
@webserver.error(400)
@webserver.error(403)
@webserver.error(404)
@webserver.error(405)
@webserver.error(408)
@webserver.error(500)
@webserver.error(505)
def customerror(error):
code = int(str(error).split(",")[0][1:])
log("Error: " + str(code),module="error")
if os.path.exists("website/errors/" + str(code) + ".html"):
return static_file("website/errors/" + str(code) + ".html",root="")
else:
with open("website/errors/generic.html") as htmlfile:
html = htmlfile.read()
# apply global substitutions
with open("website/common/footer.html") as footerfile:
footerhtml = footerfile.read()
with open("website/common/header.html") as headerfile:
headerhtml = headerfile.read()
html = html.replace("</body>",footerhtml + "</body>").replace("</head>",headerhtml + "</head>")
html = html.replace("ERROR_CODE",str(code))
return html
# this is the fallback option. If you run this service behind a reverse proxy, it is recommended to rewrite /db/ requests to the port of the db server # this is the fallback option. If you run this service behind a reverse proxy, it is recommended to rewrite /db/ requests to the port of the db server
# e.g. location /db { rewrite ^/db(.*)$ $1 break; proxy_pass http://yoururl:12349; } # e.g. location /db { rewrite ^/db(.*)$ $1 break; proxy_pass http://yoururl:12349; }
@ -89,7 +116,7 @@ def dynamic_image():
relevant, _, _, _ = KeySplit(keys) relevant, _, _, _ = KeySplit(keys)
result = resolveImage(**relevant) result = resolveImage(**relevant)
if result == "": return "" if result == "": return ""
redirect(result,301) redirect(result,307)
@webserver.route("/images/<pth:re:.*\\.jpeg>") @webserver.route("/images/<pth:re:.*\\.jpeg>")
@webserver.route("/images/<pth:re:.*\\.jpg>") @webserver.route("/images/<pth:re:.*\\.jpg>")

View File

@ -1,3 +1,3 @@
<meta name="description" content='Maloja is a self-hosted music scrobble server.' /> <meta name="description" content='Maloja is a self-hosted music scrobble server.' />
<link rel="stylesheet" href="css/maloja.css" /> <link rel="stylesheet" href="/css/maloja.css" />
<script src="javascript/search.js"></script> <script src="/javascript/search.js"></script>

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Maloja - Error ERROR_CODE</title>
</head>
<body>
<table class="top_info">
<tr>
<td class="image">
<div style="background-image:url('/favicon.png')"></div>
</td>
<td class="text">
<h1>Error ERROR_CODE</h1><br/>
<p>That did not work. Don't ask me why.</p>
</td>
</tr>
</table>
</body>
</html>