handle 500 and 401 (when using API) with our handlers

* 401 had sign up and login buttons on their page, but the page was never visible, we only show this when the API is being used
master
justcool393 2022-10-11 04:30:37 -07:00
parent e364ce8043
commit 665e6e4b21
3 changed files with 9 additions and 58 deletions

View File

@ -53,6 +53,10 @@ ERROR_MSGS = {
500: "Hiiiii it's carp! I think this error means that there's a timeout error. And I think that means something took too long to load so it decided not to work at all. If you keep seeing this on the same page <I>but not other pages</I>, then something is probably wrong with that specific function. It may not be called a function, but that sounds right to me. Anyway, ping me and I'll whine to someone smarter to fix it. Don't bother them. Thanks ily &lt;3", 500: "Hiiiii it's carp! I think this error means that there's a timeout error. And I think that means something took too long to load so it decided not to work at all. If you keep seeing this on the same page <I>but not other pages</I>, then something is probably wrong with that specific function. It may not be called a function, but that sounds right to me. Anyway, ping me and I'll whine to someone smarter to fix it. Don't bother them. Thanks ily &lt;3",
} }
ERROR_MSGS_PCM = {
500: "Hiiiii it's <b>nigger</b>! I think this error means that there's a <b>nigger</b> error. And I think that means something took too long to load so it decided to be a <b>nigger</b>. If you keep seeing this on the same page but not other pages, then something its probably a <b>niggerfaggot</b>. It may not be called a <b>nigger</b>, but that sounds right to me. Anyway, ping me and I'll whine to someone smarter to fix it. Don't bother them. Thanks ily &lt;3"
}
ERROR_MARSEYS = { ERROR_MARSEYS = {
400: "marseybrainlet", 400: "marseybrainlet",
401: "marseydead", 401: "marseydead",
@ -88,11 +92,14 @@ def error(e):
if request.headers.get("Authorization") or request.headers.get("xhr"): if request.headers.get("Authorization") or request.headers.get("xhr"):
return {"error": title, "code": e.code, "description": msg, "details": details} return {"error": title, "code": e.code, "description": msg, "details": details}
img = ERROR_MARSEYS.get(e.code, 'marseyl') img = ERROR_MARSEYS.get(e.code, 'marseyl')
if e.code == 500 and SITE_NAME == 'PCM':
msg = ERROR_MSGS_PCM.get(e.code, str(e.code))
img = "wholesome"
return render_template('errors/error.html', err=True, title=title, msg=msg, details=details, img=img), e.code return render_template('errors/error.html', err=True, title=title, msg=msg, details=details, img=img), e.code
@app.errorhandler(401) @app.errorhandler(401)
def error_401(e): def error_401(e):
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "401 Unauthorized"}, 401 if request.headers.get("Authorization") or request.headers.get("xhr"): return error(e)
else: else:
path = request.path path = request.path
qs = urlencode(dict(request.values)) qs = urlencode(dict(request.values))
@ -104,8 +111,7 @@ def error_401(e):
@app.errorhandler(500) @app.errorhandler(500)
def error_500(e): def error_500(e):
g.db.rollback() g.db.rollback()
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "500 Internal Server Error"}, 500 return error(e)
else: return render_template('errors/500.html', err=True), 500
@app.post("/allow_nsfw") @app.post("/allow_nsfw")

View File

@ -1,24 +0,0 @@
{% extends "default.html" %}
{% block title %}
<title>401 Not Authorized</title>
{% endblock %}
{% block pagetype %}error-401{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-10 col-md-5">
<div class="text-center px-3 my-8">
<img alt=":#marseydead:" loading="lazy" src="/e/marseydead.webp">
<pre></pre>
<h1 class="h5">401 Not Authorized</h1>
<p class="text-muted mb-5">What you're trying to do requires an account. I think. The original error message said something about a castle and I hated that.</p>
<div><a href="/signup" class="btn btn-primary mb-2">Create an account</a></div>
<div><a href="/login" class="text-muted text-small">Or sign in</a></div>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,31 +0,0 @@
{% extends "default.html" %}
{% block title %}
<title>500 Internal Server Error</title>
{% endblock %}
{% block pagetype %}error-500{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-10 col-md-5">
<div class="text-center px-3 my-8">
{% if SITE_NAME == 'PCM' %}
<img alt="wholesome" loading="lazy" src="/i/wholesome.webp">
{% else %}
<img alt=":#marseycarp3:" loading="lazy" src="/e/marseycarp3.webp">
{% endif %}
<pre></pre>
<h1 class="h5">500 Internal Server Error</h1>
<p class="text-muted mb-5">
{% if SITE_NAME == 'PCM' %}
Hiiiii it's <b>nigger</b>! I think this error means that there's a <b>nigger</b> error. And I think that means something took too long to load so it decided to be a <b>nigger</b>. If you keep seeing this on the same page but not other pages, then something its probably a <b>niggerfaggot</b>. It may not be called a <b>nigger</b>, but that sounds right to me. Anyway, ping me and I'll whine to someone smarter to fix it. Don't bother them. Thanks ily &lt;3
{% else %}
Hiiiii it's carp! I think this error means that there's a timeout error. And I think that means something took too long to load so it decided not to work at all. If you keep seeing this on the same page <I>but not other pages</I>, then something is probably wrong with that specific function. It may not be called a function, but that sounds right to me. Anyway, ping me and I'll whine to someone smarter to fix it. Don't bother them. Thanks ily &lt;3
{% endif %}
</p>
<div><a href="/" class="btn btn-primary">Go to the frontpage</a></div>
</div>
</div>
</div>
{% endblock %}