Refactor message hooking

This commit is contained in:
sergiuToporjinschi
2022-02-03 09:29:31 +02:00
parent 457bf990db
commit b3fee62937
7 changed files with 112 additions and 34 deletions
+13 -4
View File
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import traceback
from ast import Try
import flask
from octoprint_CalibrationTools import EStepsApi, PIDAutoTune
@@ -33,7 +36,13 @@ class API(EStepsApi.API, PIDAutoTune.API):
)
def on_api_command(self, command, data):
self._logger.debug("API command [%s] received payload [%s]", command, data)
for key, api in self.commandsRegistration.items():
if command in api["commands"]:
return api["cls"].apiGateWay(self, command, data)
try:
self._logger.debug("API command [%s] received payload [%s]", command, data)
for key, api in self.commandsRegistration.items():
if command in api["commands"]:
return api["cls"].apiGateWay(self, command, data)
except Exception as e:
self._logger.error(traceback.format_exc())
return flask.abort(500, {
"msg": "An error curred"
})