david-caro / python-foreman

Small low level python wrapper around Foreman API
GNU General Public License v2.0
57 stars 37 forks source link

Raise ObjectNotFound exception on 404 with JSON response #66

Open pief opened 8 years ago

pief commented 8 years ago

We used to always return an empty list if we got a HTTP error 404 in response to our requests, ignoring any error message possibly returned by Foreman. This makes us trigger the ObjectNotFound exception (which so far had not been used anywhere) whenever we find that the 404 is accompanied by a JSON response.

pief commented 8 years ago

Note that this will break existing applications that relied on the behavior of getting an empty list in return. With this implementation, we'll almost always raise ObjectNotFound because Foreman will always return an error in its JSON.

At least for GET requests this seems to be too high of a price to me. I'd thus still propose the alternative of not raising the exception for them as a 404 upon a GET is not really an exceptional state. Nothing "failed" here, it is perfectly valid to check if a resource exists at all.