| 12345678910111213141516171819202122232425262728293031323334 |
- """Application entrypoint."""
- from werkzeug.exceptions import HTTPException
- from app.app import create_app
- from app.exceptions.api_exception import APIException
- from app.exceptions.common_error import ServerError
- app = create_app("development")
- @app.errorhandler(Exception)
- def framework_error(e):
- """Central error handler: always return a Flask Response instance.
- Avoid returning exception objects directly (Flask expects a response).
- """
- if isinstance(e, APIException):
- return e.get_response()
- if isinstance(e, HTTPException):
- code = e.code
- msg = e.description
- error_code = 1007
- return APIException(msg, code, error_code).get_response()
- # Other exceptions: convert to ServerError in production, re-raise in debug
- if not app.config.get("DEBUG"):
- return ServerError().get_response()
- else:
- raise e
- if __name__ == "__main__":
- app.run(host="0.0.0.0", port=5000, debug=True)
|