freakboy3742 / pyxero

Python API for accessing the REST API of the Xero accounting tool.
BSD 3-Clause "New" or "Revised" License
280 stars 209 forks source link

Bad error handling in filtering #339

Closed bpotard closed 1 year ago

bpotard commented 1 year ago

Hello,

A rather confusing one; the error handling seems to be broken in (some) of the filters, leading to confusing messaging:

>>> xero.invoices.filter(IDs=["test"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/xero/basemanager.py", line 245, in wrapper
    raise XeroBadRequest(response)
  File "/usr/local/lib/python3.9/site-packages/xero/exceptions.py", line 53, in __init__
    self.errors = [payload["oauth_problem"][0]]
KeyError: 'oauth_problem'

The same call works fine with well-formed UUIDs:

>>> xeroc.xero.invoices.filter(IDs=["c681457b-8cac-4ba0-a67d-aaaaaaaaaaaa"])
[]

A little bit of digging seems to indicate that xero returns this (in "html" format): Supplied parameter 'Ids' cannot be parsed - must be of type UUID.

So it seems here xero is ignoring the "Accept" header and returning a not very helpful output. But would it be possible to support this anyway?

Cheers!

freakboy3742 commented 1 year ago

Would it be possible? Sure. Patches are welcome.