Implement error handling on EventHandler exposing APIs

This commit is contained in:
Kristóf Tóth 2018-03-07 14:45:43 +01:00
parent be6f657de1
commit 2c816d5a38
3 changed files with 18 additions and 9 deletions

View File

@ -36,6 +36,9 @@ class ProcessManagingEventHandler(TriggerlessEventHandler):
@_with_monitor_paused
def handle_event(self, key, data_json):
try:
data = data_json['data']
self.processmanager(data['command'], data['process_name'])
self.uplink.send(self.key, {'data': {'process_name': data['process_name']}})
except KeyError:
log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json))

View File

@ -84,10 +84,13 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
data['files'] = self.filemanager.files
def handle_event(self, key, data_json):
try:
data = data_json['data']
data_json['data'] = self.commands[data['command']](data)
self.attach_fileinfo(data)
return data_json
except KeyError:
log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json))
def cleanup(self):
self.monitor.stop()

View File

@ -23,8 +23,11 @@ class TerminadoEventHandler(TriggerlessEventHandler):
def handle_event(self, key, data_json):
log.debug('TerminadoEventHandler received event: {}'.format(data_json))
try:
data_json['data'] = self.commands[data_json['data']['command']](data_json['data'])
return data_json
except KeyError:
log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json))
def write(self, data):
self.terminado_server.pty.write(data['shellcmd'])