From e3529d0495b045d0275779bee18fa3d3ec62533d Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 26 Dec 2022 04:37:30 +0200 Subject: [PATCH] use abort instead of return {"error": --- files/routes/allroutes.py | 5 +++-- files/routes/posts.py | 2 +- files/routes/subs.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/files/routes/allroutes.py b/files/routes/allroutes.py index 34b1d8052..fb32f6c0d 100644 --- a/files/routes/allroutes.py +++ b/files/routes/allroutes.py @@ -27,9 +27,10 @@ def before_request(): ua = g.agent.lower() if request.host != SITE: - return {"error": "Unauthorized host provided"}, 403 + abort(403, "Unauthorized host provided!") - if request.headers.get("CF-Worker"): return {"error": "Cloudflare workers are not allowed to access this website."}, 403 + if request.headers.get("CF-Worker"): + abort(403, "Cloudflare workers are not allowed to access this website.") if not get_setting('bots') and request.headers.get("Authorization"): abort(403) diff --git a/files/routes/posts.py b/files/routes/posts.py index 919d9275b..a997e86c7 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -92,7 +92,7 @@ def post_id(pid, anything=None, v=None, sub=None): if not User.can_see(v, post): abort(403) if post.over_18 and not (v and v.over_18) and session.get('over_18', 0) < int(time.time()): - if g.is_api_or_xhr: return {"error":"Must be 18+ to view"}, 451 + if g.is_api_or_xhr: abort(451, "Must be 18+ to view") return render_template("errors/nsfw.html", v=v) if post.new: defaultsortingcomments = 'new' diff --git a/files/routes/subs.py b/files/routes/subs.py index e45663066..8fd17a22b 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -12,7 +12,7 @@ from files.__main__ import app, cache, limiter @app.post("/exile/post/") @is_not_permabanned def exile_post(v:User, pid): - if v.shadowbanned: return {"error": "Internal Server Error"}, 500 + if v.shadowbanned: abort(500) p = get_post(pid) sub = p.sub if not sub: abort(400) @@ -43,7 +43,7 @@ def exile_post(v:User, pid): @app.post("/exile/comment/") @is_not_permabanned def exile_comment(v:User, cid): - if v.shadowbanned: return {"error": "Internal Server Error"}, 500 + if v.shadowbanned: abort(500) c = get_comment(cid) sub = c.post.sub if not sub: abort(400) @@ -327,7 +327,7 @@ def create_sub2(v): return render_template("sub/create_hole.html", v=v, cost=HOLE_COST, error="You don't have enough coins!"), 403 g.db.add(v) - if v.shadowbanned: return {"error": "Internal Server Error"}, 500 + if v.shadowbanned: abort(500) sub = Sub(name=name) g.db.add(sub) @@ -348,7 +348,7 @@ def kick(v:User, pid): if not post.sub: abort(403) if not v.mods(post.sub): abort(403) - if v.shadowbanned: return {"error": "Internal Server Error"}, 500 + if v.shadowbanned: abort(500) old = post.sub post.sub = None