From a45fd815a27c88e5d73df27576cbc60412a84e72 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Feb 2022 11:46:31 +0100 Subject: [PATCH] task #2741 fix Handle error message, provider connection when we are creating an unnamed tag --- ereuse_devicehub/inventory/forms.py | 7 ++++++- ereuse_devicehub/inventory/views.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 8959ae93..d551bb0d 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1,6 +1,7 @@ import copy import json from json.decoder import JSONDecodeError +from requests.exceptions import ConnectionError from boltons.urlutils import URL from ereuse_devicehub.db import db @@ -411,7 +412,11 @@ class TagUnnamedForm(FlaskForm): def save(self): num = self.amount.data - tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)]) + try: + tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)]) + except ConnectionError: + pass + return [] tags = [Tag(id=tag_id, provider=g.inventory.tag_provider) for tag_id in tags_id] db.session.add_all(tags) db.session.commit() diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index cb80b895..40764189 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -256,7 +256,10 @@ class TagAddUnnamedView(View): context = {'page_title': 'New Unnamed Tag', 'lots': lots} form = TagUnnamedForm() if form.validate_on_submit(): - form.save() + tags = form.save() + if not tags: + msg = 'Sorry, the communication with the tag server is not possible now!' + messages.error(msg) next_url = url_for('inventory.devices.taglist') return flask.redirect(next_url)