mirror of
https://github.com/socialwifi/RouterOS-api.git
synced 2025-09-01 07:30:13 +02:00
Fix handling errors.
This commit is contained in:
parent
8aaed7589a
commit
f9eff2d8b2
2 changed files with 9 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue