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

Fallthrough to original error handler when occur unhandled exception #564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sheile
Copy link

@Sheile Sheile commented Dec 13, 2018

Problem

According to comment in code, Api#error_router should propagate exception which can't handle in flask-restplus to next error handler.
But, current implementation in handle_error suppress unhandled exception and break hierarchical error handling.

As the result, The original Flask error handler for the app, or other following error handler is NOT called.

Fixed by

Change the handle_error to propagate unhandled exception to original handler.

Reference: Api#error_router

def error_router(self, original_handler, e):
    '''
    This function decides whether the error occured in a flask-restplus
    endpoint or not. If it happened in a flask-restplus endpoint, our
    handler will be dispatched. If it happened in an unrelated view, the
    app's original error handler will be dispatched.
    In the event that the error occurred in a flask-restplus endpoint but
    the local handler can't resolve the situation, the router will fall
    back onto the original_handler as last resort.

    :param function original_handler: the original Flask error handler for the app
    :param Exception e: the exception raised while handling the request
    '''
    if self._has_fr_route():
        try:
            return self.handle_error(e)
        except Exception:
            pass  # Fall through to original handler
    return original_handler(e)

@coveralls
Copy link

coveralls commented Dec 13, 2018

Coverage Status

Coverage decreased (-0.04%) to 96.804% when pulling b67e315 on Sheile:fix/fallthrough-to-original-handler into a8f3582 on noirbizarre:master.

@Sheile Sheile force-pushed the fix/fallthrough-to-original-handler branch from b34203c to b67e315 Compare December 13, 2018 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants