flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

Error handler regiter on one namespace, but actually the error handler was registered on all namespaces.

Open YishuiLi opened this issue 5 years ago • 2 comments

Ask a question Error handler regiter on one namespace, but actually the error handler was registered on all namespaces.!

Environment

  • Python 3.6.5
  • Flask 1.1.2
  • Flask-RESTX 0.2.0

Code

from flask import Blueprint
from flask_restx import Api

from app.api.useraction import user_ns
from app.api.engine import engine_ns

api_v1 = Blueprint('api', __name__, url_prefix='/')

engine_ns = Namespace('engine', description='Engine Namespace')
user_ns = Namespace('user', description='User Namespace')

api = Api(
    api_v1,
    version='1.0',
    title='test',
    description='test',
)

api.add_namespace(user_ns)
api.add_namespace(engine_ns)
from app.base_api import api
from app.api.useraction import user_ns
from app.api.engine import engine_ns

@api.errorhandler(Exception)
def en_handle_exception(error):
    error_msg = str(error)
    return {"message": error_msg}, 500

@engine_ns.errorhandler(Exception)
def engine_exception(error):
    error_msg = "engine exception"
    return {"message": error_msg}, 500

@user_ns.errorhandler(Exception)
def user_exception(error):
    error_msg = "user exception"
    return {"message": error_msg}, 500

Result When I call the api in the Engine Namespace, the engine error handler was triggered. image

But when I call the api in the User Namespace, the engine error handler was also triggered and the user error handler wasn't triggered. image

Expected result When I call the api in the Engine Namespace, the engine error handler was triggered. image

When I call the api in the User Namespace, the user error handler was triggered. image

YishuiLi avatar Dec 25 '20 07:12 YishuiLi

This happens on version 0.4.0 too. Are there any plans to fix it? Do you guys know where the bug is? Maybe I can fix it

santalvarez avatar Aug 10 '21 17:08 santalvarez

Any news about this issue ?

luketflp avatar Oct 17 '24 21:10 luketflp