csansone / simpletrello

Simple Python wrapper to the Trello API
0 stars 0 forks source link

Simpler error messages #7

Open csansone opened 6 years ago

csansone commented 6 years ago

Wanted to see how the API responds to making an unauthorized change.

Realized that current error handling is a disaster.

>>> b2 = t.get_board('FcTw02R1')
>>> b2.name
'py-trello'
>>> b2.name = 'whatever'
ERROR:simpletrello.client:Status code 401: unauthorized permission requested on URL https://api.trello.com/1/boards/4f145d87b2f9f15d6d027b53?key=<REDACTED>&token=<REDACTED>&name=whatever
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chris/projects/simpletrello/simpletrello/boardobject.py", line 32, in name
    response = self.put(['boards', self.id], params={'name': value})
  File "/home/chris/projects/simpletrello/simpletrello/trelloobject.py", line 28, in put
    return self.client._put(*args, **kwargs)
  File "/home/chris/projects/simpletrello/simpletrello/client.py", line 129, in _put
    params=params)
  File "/home/chris/projects/simpletrello/simpletrello/client.py", line 98, in _http_request
    response.raise_for_status()
  File "/home/chris/.virtualenvs/simpletrello3/lib/python3.4/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.trello.com/1/boards/4f145d87b2f9f15d6d027b53?key=<REDACTED>&token=<REDACTED>&name=whatever
csansone commented 6 years ago

The solution to this should be to change the import in TrelloClient to

from simpletrello import exceptions

along with defining more and better exceptions.

Finally, a catch-all for unknown exceptions.

csansone commented 6 years ago

Probably a utility function to strip the sensitive key and token data from the URL so it can still be passed, logged and/or displayed without compromising same.