From ed0734cf2b2f3f1e94f005280f8fd4dde39b4523 Mon Sep 17 00:00:00 2001 From: Pieter Hollants Date: Tue, 1 Mar 2016 12:31:39 +0100 Subject: [PATCH] Raise ObjectNotFound exception on 404 except for GET requests 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. --- foreman/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/foreman/client.py b/foreman/client.py index 2b738c5..ecb164f 100644 --- a/foreman/client.py +++ b/foreman/client.py @@ -882,7 +882,9 @@ def _process_request_result(self, res): """Generic function to process the result of an HTTP request""" if res.status_code < 200 or res.status_code >= 300: if res.status_code == 404: - return [] + if res.request.method == 'GET': + return [] + raise ObjectNotFound(res, None) elif res.status_code == 406: raise Unacceptable(res, None) raise ForemanException(