macxred / cashctrl_api

Python client for the CashCtrl REST API
MIT License
0 stars 0 forks source link

Raise Error When API Request Not Successful #8

Closed lasuk closed 4 months ago

lasuk commented 4 months ago

Currently, the response of an unsuccessful API request is handed back to the caller. For example:

from cashctrl_api import CashCtrlAPIClient
cc = CashCtrlAPIClient()

response = cc.post("person/create.json", data={})

print(response.json())
## {'success': False, 'message': None, 'errors': [{'field': None, 'message': 'Either first name, last name or company must be set.'}]}

I propose that unsuccessful request lead to an error, as this is clearly not what the user expected. For example:

response = cc.post("person/create.json", data={})
APIError: 'Either first name, last name or company must be set.'