Skip to content

Commit

Permalink
Returns structured auth error.
Browse files Browse the repository at this point in the history
  • Loading branch information
braincore committed Aug 11, 2016
1 parent 28a1b68 commit 4ff8627
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dropbox/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import requests

from . import stone_serializers
from .auth import AuthError_validator
from .base import DropboxBase
from .base_team import DropboxTeamBase
from .exceptions import (
Expand Down Expand Up @@ -377,7 +378,9 @@ def request_json_string(self,
assert r.headers.get('content-type') == 'application/json', (
'Expected content-type to be application/json, got %r' %
r.headers.get('content-type'))
raise AuthError(request_id, r.json())
err = stone_serializers.json_compat_obj_decode(
AuthError_validator, r.json()['error'])
raise AuthError(request_id, err)
elif r.status_code == 429:
retry_after = r.headers.get('retry-after')
if retry_after is not None:
Expand Down
3 changes: 3 additions & 0 deletions dropbox/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def __init__(self, request_id, *args, **kwargs):
super(DropboxException, self).__init__(request_id, *args, **kwargs)
self.request_id = request_id

def __str__(self):
return repr(self)


class ApiError(DropboxException):
"""Errors produced by the Dropbox API."""
Expand Down

0 comments on commit 4ff8627

Please sign in to comment.