From 5d4cec97497eabba4a9c0802ca91a21aa1f4c690 Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Wed, 30 Mar 2022 11:55:35 -0400 Subject: [PATCH] Fix issue where ups may be set to null under certain conditions. #12 --- octoprint_ups/__init__.py | 1 - octoprint_ups/static/js/ups.js | 9 ++++++--- octoprint_ups/templates/ups_settings.jinja2 | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/octoprint_ups/__init__.py b/octoprint_ups/__init__.py index f424cb4..c763df9 100644 --- a/octoprint_ups/__init__.py +++ b/octoprint_ups/__init__.py @@ -236,7 +236,6 @@ def on_api_command(self, command, data): res = ups.list_ups() return jsonify(result=list(res.keys())) except: - # TODO: Can be done diff? idk? return make_response("Error getting UPS list", 500) diff --git a/octoprint_ups/static/js/ups.js b/octoprint_ups/static/js/ups.js index fd6a126..83b776f 100644 --- a/octoprint_ups/static/js/ups.js +++ b/octoprint_ups/static/js/ups.js @@ -134,15 +134,18 @@ $(function() { }).done(function(data) { console.log(data); self.available_upses(data.result); + }).fail(function(data) { + console.warn("Failed fetching UPS list. Falling back to config value."); + alert("Unable to fetch UPS list."); + + self.available_upses([self.settings.plugins.ups.ups()]); }); }; self.onBeforeBinding = function() { self.settings = self.settingsViewModel.settings; - }; - self.onSettingsShown = function () { - self.updateUPSList(); + self.available_upses([self.settings.plugins.ups.ups()]); }; self.onDataUpdaterPluginMessage = function(plugin, data) { diff --git a/octoprint_ups/templates/ups_settings.jinja2 b/octoprint_ups/templates/ups_settings.jinja2 index 24d5f1d..3db5528 100644 --- a/octoprint_ups/templates/ups_settings.jinja2 +++ b/octoprint_ups/templates/ups_settings.jinja2 @@ -36,7 +36,7 @@
-