Python Gunicorn重写Flask Restplus错误处理程序

Python Gunicorn重写Flask Restplus错误处理程序,python,python-3.x,flask,gunicorn,flask-restplus,Python,Python 3.x,Flask,Gunicorn,Flask Restplus,当在没有gunicron的情况下本地运行此代码时,当发生异常时,我会得到一个带有异常消息的JSON响应。当使用gunicorn运行相同的代码时,我得到的是一个HTML页面,而不是JSON Gunicorn是否覆盖默认错误处理程序?有没有一种方法可以覆盖这种行为 def create_app(): """Application factory, used to create application """ config = appconfig.AppConfig

当在没有gunicron的情况下本地运行此代码时,当发生异常时,我会得到一个带有异常消息的JSON响应。当使用gunicorn运行相同的代码时,我得到的是一个HTML页面,而不是JSON

Gunicorn是否覆盖默认错误处理程序?有没有一种方法可以覆盖这种行为

def create_app():
    """Application factory, used to create application
    """
    config = appconfig.AppConfig

    # Init connection for elastic search
    connections.create_connection(
        hosts=[config.ELASTIC_SEARCH_URI], timeout=20)

    app = Flask('Company API')
    app.config.from_object(config)
    app.debug = config.APP_DEBUG
    app.db = SQLAlchemy(app)
    app.migrate = Migrate(app, app.db, directory=config.MIGRATION_DIR)  # this
    app.mongo_db = connect(config.MONGO_DBNAME, host=config.MONGO_DATABASE_URI)

    # Swagger Doc Authorization
    authorizations = {
        "bearer token": {
            "type": "apiKey",
            "in": "header",
            "name": "authorization"
        }
    }

    # Add URL Int List Converter
    app.url_map.converters['list'] = ListConverter
    app.url_map.converters['int_list'] = IntListConverter

    app.api = Api(app, version='1', authorizations=authorizations)
    app.wsgi_app = ProxyFix(app.wsgi_app)

    return app


app = create_app()


@app.api.errorhandler(CompnayError)
def autods_error_handler(error):
    return {'errors': error.description}, error.code


@app.api.errorhandler(Exception)
def default_error_handler(error):
    code = error.code if hasattr(error, 'code') else 500
    return {'errors': "{}: {}".format(type(error).__name__, str(error))}, code