getlago / lago-python-client

Python wrapper for the Lago Rest API
MIT License
20 stars 10 forks source link

Uninformative exceptions #266

Closed slavaGanzin closed 6 days ago

slavaGanzin commented 2 weeks ago

Python is usually inferior in properly describing what happened, but your client is a gem. What the fuck should I understand from your exception?


Traceback (most recent call last):
  File "/Users/slava/work/helpmetest2/robot/listener.py", line 381, in <module>
    bill('MyAwesomeCompany:123233:1q123123')
  File "/Users/slava/work/helpmetest2/robot/helpers.py", line 44, in bill
    client.events.create(Event(
  File "/Users/slava/work/helpmetest2/.venv/lib/python3.12/site-packages/lago_python_client/mixins.py", line 58, in create
    response_data = get_response_data(response=api_response, key=self.ROOT_NAME)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/slava/work/helpmetest2/.venv/lib/python3.12/site-packages/lago_python_client/services/response.py", line 69, in get_response_data
    response_or_None: Optional[Response] = verify_response(response)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/slava/work/helpmetest2/.venv/lib/python3.12/site-packages/lago_python_client/services/response.py", line 53, in verify_response
    raise LagoApiError(
lago_python_client.exceptions.LagoApiError

And plain request gives me an answer: {'status': 422, 'error': 'Unprocessable Entity', 'code': 'validation_errors', 'error_details': {'transaction_id': ['value_already_exist']}}

jdenquin commented 2 weeks ago

I agree this exception is really bad and does not represent the actual error, we're taking a look at it

vincent-pochet commented 6 days ago

Thank you for reporting this @slavaGanzin The error management will be improved with the next release of this client.