diff --git a/app/__init__.py b/app/__init__.py index afa61bcb..23186789 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -114,3 +114,7 @@ from .utils import clearNotifications def check_for_notifications(): if current_user.is_authenticated: clearNotifications(request.path) + +@app.errorhandler(404) +def page_not_found(e): + return render_template("404.html"), 404 diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index adca61a4..4beec0af 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from flask import request, jsonify, current_app, abort +from flask import request, jsonify, current_app from flask_login import current_user, login_required from sqlalchemy.sql.expression import func @@ -115,11 +115,11 @@ def topic_set_discard(): tid = request.args.get("tid") discard = request.args.get("discard") if tid is None or discard is None: - abort(400) + error(400, "Missing topic ID or discard bool") topic = ForumTopic.query.get(tid) if not topic.checkPerm(current_user, Permission.TOPIC_DISCARD): - abort(403) + error(403, "Permission denied, need: TOPIC_DISCARD") topic.discarded = discard == "true" db.session.commit() @@ -151,13 +151,13 @@ def list_all_releases(): if "author" in request.args: author = User.query.filter_by(username=request.args["author"]).first() if author is None: - abort(404) + error(404, "Author not found") query = query.filter(PackageRelease.package.has(author=author)) if "maintainer" in request.args: maintainer = User.query.filter_by(username=request.args["maintainer"]).first() if maintainer is None: - abort(404) + error(404, "Maintainer not found") query = query.join(Package) query = query.filter(Package.maintainers.any(id=maintainer.id)) diff --git a/app/flatpages/help/api.md b/app/flatpages/help/api.md index ef9503ea..6e5693cc 100644 --- a/app/flatpages/help/api.md +++ b/app/flatpages/help/api.md @@ -122,8 +122,8 @@ Supported query parameters: * `min_minetest_version`: dict or null, minimum supported minetest version (inclusive). * `max_minetest_version`: dict or null, minimum supported minetest version (inclusive). * `package` - * `author`: author username. - * `name` + * `author`: author username + * `name`: technical name * `type`: `mod`, `game`, or `txp` * GET `/api/packages///releases/` (List) * Returns array of release dictionaries, see above, but without package info. diff --git a/app/templates/404.html b/app/templates/404.html new file mode 100644 index 00000000..5d44ec1b --- /dev/null +++ b/app/templates/404.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} + +{% block title %} + Page not found +{% endblock %} + +{% block content %} +

Page not found

+

+ That page could not be found. The link may be broken, the page may have been deleted, + or you may not have access to it. +

+{% endblock %}