bbangert / velruse

Simplifying third-party authentication for web applications.
http://packages.python.org/velruse/index.html
MIT License
252 stars 86 forks source link

ThirdPartyFailure is raised when something gows wrong with provider, but there's no way to catch it. #144

Open sq9mev opened 10 years ago

sq9mev commented 10 years ago

There may be many reasons when ThirdPartyFailure raises, eg. generaly it's used in providers when response code from provider is not 200.

Well, eg. Looking at velruse source i can see no way to catch such en exceptions in my own code, so i can not display human readable message and show it to user - instead ugly 500 appears.

Shouldn't be some way added to catch ThirdPartyFailure eg, just the way velruse.AuthenticationDenied view is set up?

czekan commented 10 years ago

The reasonable solution is to return ThirdPartyFailure (and other exceptions that inherit from VelruseException) than raise it. Than we could register view in our application which will handle the errors the same way we handle AuthenticationComplete and AuthenticationDenied. Eg.:

@view_config(
    context='velruse.exceptions.VelruseException',
    renderer='app:templates/social_login_error.html',
)
def login_error_view(request):
    # do something with it, eg. redirect to home and flash message
    error = request.context.message
    request.session.flash({'type': 'danger', 'messages': [error, ]})
    log.warning(request.context)
    return HTTPFound(location=request.route_url('home'))

We've got fork of forked repo :)(with linkedin_oauth2 support), which includes those changes: https://github.com/codersmill/velruse/tree/feature/handling_errors

I can prepare proper Pull Request if maintainer accept this solution.