Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
better error handling for OAuth1 platforms like Twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Apr 2, 2015
1 parent 9c91f6b commit 8c2c1ef
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gratipay/elsewhere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from aspen import log, Response
from aspen.utils import to_age, utc
from oauthlib.oauth2 import TokenExpiredError
from requests_oauthlib import OAuth1Session, OAuth2Session

from gratipay.elsewhere._extractors import not_available
Expand Down Expand Up @@ -122,6 +123,11 @@ def api_get(self, path, sess=None, **kw):

# Check response status
status = response.status_code
if status == 401 and isinstance(self, PlatformOAuth1):
# https://tools.ietf.org/html/rfc5849#section-3.2
if is_user_session:
raise TokenExpiredError
raise Response(500)
if status == 404:
raise Response(404, response.text)
if status == 429 and is_user_session:
Expand Down

0 comments on commit 8c2c1ef

Please sign in to comment.