Fix handling errors.

This commit is contained in:
Jakub Skiepko 2014-06-26 13:34:06 +02:00
parent 8aaed7589a
commit f9eff2d8b2
2 changed files with 9 additions and 4 deletions

View file

@ -65,11 +65,12 @@ class ApiCommunicator(object):
if response.type == 'done':
asynchronous_response.done = True
elif response.type == 'trap':
asynchronous_response.done = True
asynchronous_response.error = response.attributes['message']
elif response.type == 'fatal':
del(self.response_buffor[tag])
raise exceptions.RouterOsApiConnectionClosedError()
message = "Fatal error executing command {}".format(
asynchronous_response.command)
raise exceptions.RouterOsApiConnectionClosedError(message)
def receive_synchronous(self):
return self.receive_asynchronous('synchronous')
@ -80,8 +81,9 @@ class ApiCommunicator(object):
self.process_single_response()
del(self.response_buffor[tag])
if response.error:
raise exceptions.RouterOsApiCommunicationError(
response.error.decode())
message = "Error \"{}\" executing command {}".format(
response.error.decode(), response.command)
raise exceptions.RouterOsApiCommunicationError(message)
else:
if not response.binary:
response.decode()

View file

@ -76,3 +76,6 @@ class CommandSentence(object):
for key, value in kwargs.items():
self.queries.add(query.IsEqualQuery(key, value))
def __str__(self):
return ' '.join(self.get_api_format())