add 405 handler

This commit is contained in:
2026-05-28 21:40:46 +03:00
parent 0224e2e390
commit 572e6e86c4

View File

@@ -149,6 +149,13 @@ def clear_stale_sessions():
for sess in stale_sessions: for sess in stale_sessions:
sess.delete() sess.delete()
def clear_api_limits():
from .db import db
from .models import APIRateLimits
with db.transaction():
limits = APIRateLimits.select()
for l in limits:
l.delete()
cache = Cache() cache = Cache()
@@ -223,6 +230,7 @@ def create_app():
create_deleted_user() create_deleted_user()
clear_stale_sessions() clear_stale_sessions()
clear_api_limits()
reparse_babycode() reparse_babycode()
@@ -320,6 +328,15 @@ def create_app():
else: else:
return render_template('common/404.html'), e.code return render_template('common/404.html'), e.code
@app.errorhandler(405)
def _handle_405(e):
if request.path.startswith('/hyperapi/'):
return '<h1>method not allowed</h1>', e.code
elif request.path.startswith('/api/'):
return {'error': 'method not allowed'}, e.code
else:
return render_template('common/404.html'), e.code
@app.errorhandler(403) @app.errorhandler(403)
def _handle_403(e): def _handle_403(e):
if request.path.startswith('/hyperapi/'): if request.path.startswith('/hyperapi/'):