QhueException doesn't pass error codes
Closed this issue · 3 comments
Hi,
Thanks very much for your API, I've been using it extensively in my projects.
I noticed that QhueException only returns the error description and not the error type/code. I often get error "201", which happens if you try to do change a param on a light which is off. In my use case it's not actually an error and I want to ignore it.
Hue's error descriptions strings are a bit annoying to parse and have changed on me in the past. If the exception returned the error type/number that is documented here, it would make exceptions a bit easier to handle.
Ah yes - I like that. I think the type ID may be a new field since I first wrote this.
Have added it to the develop branch, and will merge it into master shortly as part of the 2.0 release.
Oh, I should say that there's one potential complication here: In theory, one call can return multiple errors from the API, so what you actually get back is a list. I just concatenate the relevant description messages with newlines between them to get the message that's included in the exception.
For the type ID and the address fields, though, it seems messy to include lists in the exception, so I assume that in the vast majority of cases there will only be one error per call, and set their values from the first, and hopefully only, error.
Your implementation should work fine for my usecase, but just to give you more context, I do have a use case that does return two errors pretty often: if you try to post two state changes to a light that's off. For example:
self.bridge.lights[light].state(xy=xy, transitiontime=transitionTime)
will return error 201 twice, with a different description for each, for example:
parameter, xy, is not modifiable. Device is set to off.
parameter, bri, is not modifiable. Device is set to off.
Since both errors have the same error ID (201), your approach is perfect for me. I personally haven't seen any cases where it returns different errors at once.