From 749c845a1b6851a104bd533873a34f6f89925821 Mon Sep 17 00:00:00 2001 From: Anna Bocharova Date: Sun, 22 Oct 2023 14:17:51 +0000 Subject: [PATCH] Fixing the missing reason for API faulty response on disabled relay update. --- octoprint_octorelay/__init__.py | 4 ++-- tests/test_init.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/octoprint_octorelay/__init__.py b/octoprint_octorelay/__init__.py index 2b50ada5..3664e34d 100755 --- a/octoprint_octorelay/__init__.py +++ b/octoprint_octorelay/__init__.py @@ -188,8 +188,8 @@ def on_api_command(self, command, data): return flask.jsonify({ "status": "ok", "result": state }) # todo remove branch when dropping v1 return flask.jsonify({ "status": state }) except HandlingException as exception: # todo: deprecate the behavior for 400, only abort in next version - if version == 1 and exception.status == 400: - return flask.jsonify({ "status": "error" }) # todo remove this branch when dropping v1 + if version == 1 and exception.status == 400: # todo remove this branch when dropping v1 + return flask.jsonify({ "status": "error", "reason": f"Can not toggle the relay {subject}" }) return flask.abort(exception.status) # API command to cancel the postponed toggling task if command == CANCEL_TASK_COMMAND: diff --git a/tests/test_init.py b/tests/test_init.py index e38e4757..999d43fd 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1099,7 +1099,7 @@ def test_on_api_command__update_exceptions(self, jsonify_mock, abort_mock): "payload": { "pin": "r4" }, "status": 400, "expectedMethod": jsonify_mock, - "expectedArgument": { "status": "error"} + "expectedArgument": { "status": "error", "reason": "Can not toggle the relay r4" } }, { "payload": { "v": 2, "subject": "r4" },