Primer commit
This commit is contained in:
39
main.py
Normal file
39
main.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import functools
|
||||||
|
import io
|
||||||
|
|
||||||
|
import flask
|
||||||
|
|
||||||
|
from werkzeug.wsgi import FileWrapper
|
||||||
|
|
||||||
|
import dibuixa
|
||||||
|
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPError(flask.Response, Exception):
|
||||||
|
def __init__(self, *args, status_code, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.status_code = status_code
|
||||||
|
|
||||||
|
|
||||||
|
def handle_errors(func):
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapped(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except HTTPError as r:
|
||||||
|
return r, r.status_code
|
||||||
|
except Exception:
|
||||||
|
return flask.Response("Oh no! Hi ha hagut un error en el servidor :(", status="Internal error"), 500
|
||||||
|
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
@handle_errors
|
||||||
|
def hola(code):
|
||||||
|
return "Hola"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
Reference in New Issue
Block a user