diff --git a/app.py b/app.py index 1b102e4..0eb1c29 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,7 @@ import os from dataclasses import dataclass from pathlib import Path -from flask import Flask, jsonify, render_template, send_from_directory +from flask import Flask, jsonify, render_template, send_from_directory, abort from pygments import highlight from pygments.formatters import HtmlFormatter from pygments.lexers import TextLexer, get_lexer_for_filename @@ -102,7 +102,7 @@ def serve_gist(filename): file_path = os.path.join(GIST_PATH, filename) if not os.path.exists(file_path) or not os.path.isfile(file_path): - return "File not found", 404 + abort(404) try: with open(file_path, "r", encoding="utf-8") as f: @@ -122,6 +122,11 @@ def serve_gist(filename): return render_template("gist.html", filename=filename, highlighted_code=highlighted) +@app.errorhandler(404) +def not_found(error): + return render_template("404.html"), 404 + + @app.route("/api/repo/") def get_repo(repo_id): repositories = [repo for repo in get_repositories() if repo.exported] diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..03ab0bc --- /dev/null +++ b/templates/404.html @@ -0,0 +1,36 @@ + + + + + + + + + + 404 - Not Found + + + +
+

404

+
+ + + + + \ No newline at end of file