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

OAuthException in a decorator can't be handled

Open jace opened this issue 14 years ago • 2 comments
trafficstars

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

jace avatar Aug 23 '11 06:08 jace

+1

I had to manually apply the decorator and it was a real pain.

I have 2 suggestions:

  1. 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.
  2. 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.

aviflax avatar Apr 26 '13 19:04 aviflax

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.

yannk avatar Sep 03 '13 19:09 yannk