flask-oauth
flask-oauth copied to clipboard
OAuthException in a decorator can't be handled
The authorized_handler method raises OAuthException if the OAuth process fails. However, since this method is a decorator, there's no way to write an exception handler that can display a friendly error message to the user. Instead, the user sees a 500 internal server error.
Relevant code: https://github.com/mitsuhiko/flask-oauth/blob/master/flaskext/oauth.py#L305
+1
I had to manually apply the decorator and it was a real pain.
I have 2 suggestions:
- Split the decorators into 2 methods: one for the functionality, one which makes it a decorator. That way if one wanted to, one could easily just call the “functionality” method and just use its return value.
- Have the decorators catch all exceptions which occur before calling the wrapped function, and if an exception is raised, just pass it to the wrapped function in a specific named argument. (Similar to Node callbacks.) The wrapped functions can then just check whether the error arg is not None and if so deal with it.
I wrapped the decorator with another decorator (trapping this very exception) but it's not ideal, I agree. It would be nice to have a authorize() method returning the data, or throwing whatever exception.