Obsessive error handling

This commit is contained in:
2024-02-26 10:25:25 -06:00
parent b19062eb65
commit dd4eb883d2
2 changed files with 53 additions and 3 deletions

26
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Flask",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}/src",
"module": "flask",
"env": {
"FLASK_APP": "app.py",
"FLASK_DEBUG": "1",
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}

View File

@@ -2,11 +2,14 @@ import flask
from flask_minify import Minify from flask_minify import Minify
import json import json
from tasks import TaskHandler from tasks import TaskHandler
import werkzeug.exceptions as HTTPerror
proj = json.load(open("./static/json/projects.json", "r")) proj = json.load(open("./static/json/projects.json", "r"))
books = json.load(open("./static/json/books.json", "r")) books = json.load(open("./static/json/books.json", "r"))
skillList = json.load(open("./static/json/skills.json", "r"))
timeline = json.load(open("./static/json/timeline.json", "r")) timeline = json.load(open("./static/json/timeline.json", "r"))
pages = json.load(open("./static/json/pages.json", "r")) pages = json.load(open("./static/json/pages.json", "r"))
pages['about']['skillList'] = skillList
pages['about']['timeline'] = timeline pages['about']['timeline'] = timeline
pages['projects']['projects'] = proj pages['projects']['projects'] = proj
pages['home']['books'] = books pages['home']['books'] = books
@@ -20,14 +23,35 @@ tasks = TaskHandler()
@app.route('/api/goto/<location>') @app.route('/api/goto/<location>')
def goto(location='home'): def goto(location='home'):
pagevars = pages[location] pagevars = pages[location]
return [pagevars, flask.render_template(pagevars["template"], var=pagevars)] page = None
try:
page = flask.render_template(pagevars["template"], var=pagevars)
except Exception as e:
e = HTTPerror.InternalServerError(None, e)
page = page404(e)
return [pagevars, page]
# I am literally insane # I am literally insane
# There was no reason for me to do this # There was no reason for me to do this
# it saved some lines of code I guess # it saved some lines of code I guess
# infinite flaskless flask here we comes # infinite flaskless flask here we comes
def funcGen(pagename, pages):
def dynamicRule():
try:
return flask.render_template('header.html', var=pages[pagename])
except Exception:
e = HTTPerror.InternalServerError()
return page404(e)
return dynamicRule
for i in pages: for i in pages:
exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])") func = funcGen(i, pages)
app.add_url_rule(pages[i]['canonical'], i, func)
# for i in pages:
# exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])")
@app.route("/resume") @app.route("/resume")