ginger.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Application entrypoint."""
  2. import os
  3. from werkzeug.exceptions import HTTPException
  4. from app.app import create_app
  5. from app.exceptions.api_exception import APIException
  6. from app.exceptions.common_error import ServerError
  7. app = create_app(os.getenv("FLASK_ENV", "development"))
  8. @app.errorhandler(Exception)
  9. def framework_error(e):
  10. """Central error handler: always return a Flask Response instance.
  11. Avoid returning exception objects directly (Flask expects a response).
  12. """
  13. if isinstance(e, APIException):
  14. return e.get_response()
  15. if isinstance(e, HTTPException):
  16. code = e.code
  17. msg = e.description
  18. error_code = 1007
  19. return APIException(msg, code, error_code).get_response()
  20. # Other exceptions: convert to ServerError in production, re-raise in debug
  21. if not app.config.get("DEBUG"):
  22. return ServerError().get_response()
  23. else:
  24. raise e
  25. if __name__ == "__main__":
  26. app.run(host="0.0.0.0", port=5000, debug=app.config.get("DEBUG", False), use_reloader=False)