Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion icinga2api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,18 @@ def _request(self, method, url_path, payload=None, stream=False):
# pprint(response)

if not 200 <= response.status_code <= 299:
try:
upstream_error=response.json()
except ValueError:
upstream_error=None
raise Icinga2ApiException(
'Request "{}" failed with status {}: {}'.format(
response.url,
response.status_code,
response.text,
))
),
upstream_error=upstream_error,
)

if stream:
return response
Expand All @@ -153,6 +159,7 @@ def _get_message_from_stream(stream):
# TODO: test iter_lines()
message = ''
for char in stream.iter_content():
char = char.decode()
if char == '\n':
yield message
message = ''
Expand Down
3 changes: 2 additions & 1 deletion icinga2api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class Icinga2ApiException(Exception):
Icinga 2 API exception class
'''

def __init__(self, error):
def __init__(self, error, upstream_error=None):
super(Icinga2ApiException, self).__init__(error)
self.error = error
self.upstream_error = upstream_error

def __str__(self):
return str(self.error)
Expand Down