summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-24 19:57:53 +0300
committerEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-24 19:57:53 +0300
commit890fb73d88b2cf290df947a7438be87a73fb92b5 (patch)
tree455a6d8e5b9e371508c35f336c1e434b96f31abc
parentd05b7b3ca5452d5bf7d66c1cd9da0cc4b368180f (diff)
adding touches to base class, causes to crash when error response is received without info
-rw-r--r--pyagl/services/base.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/pyagl/services/base.py b/pyagl/services/base.py
index ce5c8c7..091a9aa 100644
--- a/pyagl/services/base.py
+++ b/pyagl/services/base.py
@@ -64,33 +64,26 @@ class AFBResponse:
raise ValueError(f'Received a response with non-numeric message id {data[1]}')
else:
self.msgid = int(data[1])
- self.status = data[2]['request']['status']
- if 'info' in data[2]['request']:
- self.info = data[2]['request']['info']
- if 'response' in data[2]:
- self.data = data[2]['response']
+ self.status = data[2]['request'].get('status')
+ self.info = data[2]['request'].get('info')
elif self.type == AFBT.EVENT:
self.api = data[1]
- if 'data' in data[2]:
- self.data = data[2]['data']
+ self.data = data[2].get('data')
elif self.type == AFBT.ERROR:
logging.debug(f'AFB returned erroneous response {data}')
self.msgid = int(data[1])
- self.status = data[2]['request']['status']
- self.info = data[2]['request']['info']
+ self.status = data[2]['request'].get('status')
+ self.info = data[2]['request'].get('info')
- if 'response' in data[2]:
- self.data = data[2]['response']
+ self.data = data[2].get('response')
def __str__(self): # for debugging purposes
if self.type == AFBT.EVENT:
- return f'[{self.type.name}][{self.api}][Data: {self.data if hasattr(self, "data") else None}]'
+ return f'[{self.type.name}][{self.api}][Data: {self.data}]'
else:
- return f'[{self.type.name}][Status: {self.status}][{self.msgid}]' \
- f'[Info: {self.info if hasattr(self,"info") else None}]' \
- f'[Data: {self.data if hasattr(self, "data") else None}]'
+ return f'[{self.type.name}][Status: {self.status}][{self.msgid}][Info: {self.info}][Data: {self.data}]'
class AGLBaseService: