Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handlers on namespaces causes error #141

Closed
3art opened this issue Mar 1, 2016 · 2 comments
Closed

Error handlers on namespaces causes error #141

3art opened this issue Mar 1, 2016 · 2 comments
Labels
bug
Milestone

Comments

@3art
Copy link

@3art 3art commented Mar 1, 2016

Flask-restplus=0.9.0

When error handlers are registered on a namespace and afterwards are transfered to api an error occurs. I got it working on my side by adding ".items()" on api.py:398:
for exception, handler in ns.error_handlers.items():

Due to the lack of time I cannot go through the contribution process myself.

More info:
For example when registering my error handler for a specific exception

namespace = Namespace('endpoint')

@namespace.errorhandler(ConflictExceptionClass)
def handle_conflict_exception(error):
...

When starting the program you will get:

    api.add_namespace(ns_engine)
  File "/home/bevandeba/tools/python/local/lib/python2.7/site-packages/flask_restplus/api.py", line 398, in add_namespace
    for exception, handler in ns.error_handlers:
TypeError: 'type' object is not iterable

This issue is located at
api.py:397-399:

        # Register error handlers
        for exception, handler in ns.error_handlers:
            self.error_handlers[exception] = handler

Fixed by changing to:

        # Register error handlers
        for exception, handler in ns.error_handlers.items():
            self.error_handlers[exception] = handler
@dmulter

This comment has been minimized.

Copy link

@dmulter dmulter commented Mar 9, 2016

I've got the same issue. I made the fix above directly in my virtualenv files (Flask-RESTPlus 0.9.0) and I no longer get the TypeError, but...

When my code throws the custom exception, I get this AssertionError in Flask. Note that without the handler, I do see my unhandled custom exception being thrown correctly.

--------------------------------------------------------------------------------
ERROR in app [/.../PROJECT/.virtualenv/lib/python2.7/site-packages/flask/app.py:1423]:
Exception on /hardware/2 [GET]
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/.../PROJECT/.virtualenv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/.../PROJECT/.virtualenv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/.../PROJECT/.virtualenv/lib/python2.7/site-packages/flask_restplus/api.py", line 537, in error_router
    return original_handler(e)
  File "/.../PROJECT/.virtualenv/lib/python2.7/site-packages/flask/app.py", line 1363, in handle_user_exception
    assert exc_value is e
AssertionError
@funcmike

This comment has been minimized.

Copy link

@funcmike funcmike commented Mar 15, 2016

I can confirm this issue.
With patch ns.error_handlers.items() error handlers in namespaces working fine for me.

noirbizarre added a commit that referenced this issue Apr 8, 2016
Fix namespace error handlers (fixes #141)
@noirbizarre noirbizarre added the bug label Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.