mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 14:18:12 +02:00
now errors are sent with json form instead of html
This commit is contained in:
@ -5,7 +5,7 @@ from flask_socketio import SocketIO
|
|||||||
from routes.index import router as index_router
|
from routes.index import router as index_router
|
||||||
from routes.answers import router as answers_router
|
from routes.answers import router as answers_router
|
||||||
from routes.datasets import router as datasets_router
|
from routes.datasets import router as datasets_router
|
||||||
|
from werkzeug.exceptions import HTTPException
|
||||||
import os
|
import os
|
||||||
|
|
||||||
app = Flask(__name__, static_folder='../public', static_url_path='/')
|
app = Flask(__name__, static_folder='../public', static_url_path='/')
|
||||||
@ -17,6 +17,22 @@ app.register_blueprint(answers_router) # mounts at '/answers'
|
|||||||
app.register_blueprint(datasets_router) # mounts at '/datasets'
|
app.register_blueprint(datasets_router) # mounts at '/datasets'
|
||||||
|
|
||||||
|
|
||||||
|
@app.errorhandler(Exception)
|
||||||
|
def handle_exception(e):
|
||||||
|
if isinstance(e, HTTPException):
|
||||||
|
response = {
|
||||||
|
"error": e.name.lower().replace(" ", "_"), # e.g. "not_found"
|
||||||
|
"message": e.description,
|
||||||
|
}
|
||||||
|
return app.json.response(response), e.code or 500
|
||||||
|
|
||||||
|
app.logger.exception(e)
|
||||||
|
return (
|
||||||
|
app.json.response({"error": "internal_server_error", "message": str(e)}),
|
||||||
|
500,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def init_socketio(app):
|
def init_socketio(app):
|
||||||
socketio = SocketIO(app, cors_allowed_origins='*')
|
socketio = SocketIO(app, cors_allowed_origins='*')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user