use abort instead of return {"error":

master
Aevann 2022-12-26 04:37:30 +02:00
parent 99715c7559
commit e3529d0495
3 changed files with 8 additions and 7 deletions

View File

@ -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)

View File

@ -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'

View File

@ -12,7 +12,7 @@ from files.__main__ import app, cache, limiter
@app.post("/exile/post/<pid>")
@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/<cid>")
@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