updates, back and front
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
from flask import Flask, send_from_directory
|
||||
from flask import Flask, send_from_directory, jsonify
|
||||
from werkzeug.exceptions import HTTPException, NotFound, BadRequest
|
||||
from sqlalchemy import text
|
||||
|
||||
from .extensions import db, migrate, cors
|
||||
@@ -35,6 +36,21 @@ def create_app(config_name=None):
|
||||
if path and os.path.exists(os.path.join(static_folder, path)):
|
||||
return send_from_directory(static_folder, path)
|
||||
return send_from_directory(static_folder, 'index.html')
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
return jsonify({'error': 'Resource not found', 'message': str(e)}), 404
|
||||
|
||||
@app.errorhandler(400)
|
||||
def bad_request(e):
|
||||
return jsonify({'error': 'Bad request', 'message': str(e)}), 400
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def handle_exception(e):
|
||||
if isinstance(e, HTTPException):
|
||||
return jsonify({'error': e.name, 'message': e.description}), e.code
|
||||
app.logger.error(f"Unhandled exception: {str(e)}", exc_info=True)
|
||||
return jsonify({'error': 'Internal server error', 'message': 'An unexpected error occurred'}), 500
|
||||
|
||||
return app
|
||||
|
||||
|
||||
Reference in New Issue
Block a user