Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ObjectNotFound exception on 404 with JSON response #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Raise ObjectNotFound exception on 404 with JSON response #66

wants to merge 1 commit into from

Conversation

pief
Copy link
Contributor

@pief pief commented Mar 1, 2016

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
Copy link
Contributor Author

pief commented Mar 1, 2016

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.

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.

For GET requests this is desirable because trying to GET a non-existant
resource (eg. using a ID specified by the user) is perfectly normal and does
not justify raising an exception. For other requests (especially POST) it is
and thus we now raise the ObjectNotFound exception (which so far had not been
used anywhere) for anything but GET requests when a 404 is encountered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant