2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +00:00

Label printing errors (#6450)

* Enhance error handling for label printing

* Better feedback in forms

* Raise error to user - no need to log
This commit is contained in:
Oliver
2024-02-08 11:37:06 +11:00
committed by GitHub
parent 4e58f0a3c7
commit 8b62f7b2c0
2 changed files with 28 additions and 7 deletions

View File

@ -4,6 +4,7 @@ from django.core.exceptions import FieldError, ValidationError
from django.http import JsonResponse
from django.urls import include, path, re_path
from django.utils.decorators import method_decorator
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import cache_page, never_cache
from django_filters.rest_framework import DjangoFilterBackend
@ -13,6 +14,7 @@ from rest_framework.request import clone_request
import build.models
import common.models
import InvenTree.exceptions
import InvenTree.helpers
import label.models
import label.serializers
@ -232,9 +234,14 @@ class LabelPrintMixin(LabelFilterMixin):
# At this point, we offload the label(s) to the selected plugin.
# The plugin is responsible for handling the request and returning a response.
result = plugin.print_labels(
label, items_to_print, request, printing_options=request.data
)
try:
result = plugin.print_labels(
label, items_to_print, request, printing_options=request.data
)
except ValidationError as e:
raise (e)
except Exception as e:
raise ValidationError([_('Error printing label'), str(e)])
if isinstance(result, JsonResponse):
result['plugin'] = plugin.plugin_slug()