ginger.py 972 B

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